您的位置:首页 > 其它

其他CTF题目(记录备忘)

2015-08-30 15:20 417 查看
1、ISG2014 SQLMAP Misc 100

附件文件下载:http://www.2cto.com/uploadfile/2014/1013/20141013055722355.zip

题目给了一个sqlmap数据包,查看发现是通过逐位猜解的方式获得key,语句类似

/message.php?id=1 AND ORD(MID((SELECT IFNULL(CAST(`value` AS CHAR),0x20) FROM isg.flags ORDER BY `value` LIMIT 0,1),34,1))>1


首先将pcap包的字符串导出,指令为:

strings sqlmap.pcap | grep isg.flags > 11.txt


将前面的几行去掉,从正式猜解句:GET /message.php?id=1 AND ORD(MID((SELECT IFNULL(CAST(
value
AS CHAR),0x20) FROM isg.flags ORDER BY
value
LIMIT 0,1),1,1))>64 开始。将pcap文件中的http对象导出来,文件内容类似:

Message #1 AND ORD(MID((SELECT IFNULL(CAST(`value` AS CHAR),0x20) FROM isg.flags ORDER BY `value` LIMIT 0,1),1,1))>64: The quick brown fox jumps over the lazy dog


若条件成立,则会显示后面的The quick brown fox jumps over the lazy dog,若不成功则不显示。读取每个文件的内容保存为12.txt

编写代码如下:

import re
import os

f=open("12.txt",'w')
files = os.listdir()
for name in files:
f1=open(name,'r')
x=f1.read()
f.write(x+"\n")
f1.close()

f.close()

f=open("11.txt",'r')
f1=open("12.txt",'r')
content=f1.read()
f1.close()
fw=open("13.txt",'w')
lastpos,nowpos=1,1
lastchar,nowchar=64,64
lastline=''
flags=''
for l in f.readlines():
m=re.search(r"%29%2C(\d+)%2C\S*%3E(\d+)\s",l) #匹配字符位置和比较数
if m:
nowchar=int(m.group(2))
nowpos=int(m.group(1))
d="%d,1\S*%d:\s(\S+)"%(lastpos,lastchar)  #匹配后面的The quick....
m1=re.search(d,content)
if(nowpos!=lastpos):
if(m1):
fw.write("%d:%c,,,%s\n"%(lastpos,chr(lastchar),m1.group(1)))
flags+=chr(lastchar+1) #匹配了,说明>条件成立,故字符+1
else:
fw.write("%d:%c\n"%(lastpos,chr(lastchar)))#不匹配,说明不成功,不需加1
flags+=chr(lastchar)
lastline=l
lastpos=nowpos
lastchar=nowchar

f.close()
fw.close()
print flags


得到key为ISG{BLind_SQl_InJEcTi0N_DeTEcTEd}

另外,还有种方法,可以直接分析pcap文件,找到数据位置,按照gzip解压再匹配识别:

import zlib
import re
f=open('sqlmap.pcap','rb')
c=f.read()
f.close()
mlist=re.finditer(r"Content-Length: (\d+)",c)
lastpos,nowpos=1,1
lastchar,nowchar=64,64
lastline=''
flags=''
for mx in mlist:
if(int(mx.group(1))<100):#长度小于100,应该不是需要的字符串
continue
mc=c[mx.span()[1]+48:mx.span()[1]+48+int(mx.group(1))]#按照content-length长度来读取相应字符数
content=zlib.decompress(mc,16+zlib.MAX_WBITS)#gzip解压
#print content
m=re.search('0,1\),(\d+).*>(\d+):',content) #匹配判断的字符和字符位置
if(m is None):
continue
nowchar=int(m.group(2)) #当前判断的字符ACII值
nowpos=int(m.group(1)) #位置
if(nowpos!=lastpos): #跳到下个字符位置,说明该位置判断已结束
d=">\d+:\s(\S+)"#匹配后面的The quick....
m1=re.search(d,lastline)#保存的上一行中寻找
if m1 is not None:
flags+=chr(lastchar+1) #匹配到后面的Fox
else:
flags+=chr(lastchar) #未匹配到Fox
lastpos=nowpos
lastchar=nowchar
lastline=content
print 'Flag is '+flags
#Flag is ISG{BLind_SQl_InJEcTi0N_DeTEcTEd}


2、ISG 2014:哼

给了一个图片,binwalk发现有两张图

@kali:~/Desktop$ binwalk final.png

DECIMAL       HEXADECIMAL     DESCRIPTION
-------------------------------------------------------------
0             0x0             PNG image, 1440 x 900, 8-bit/color RGB, non-interlaced
41            0x29            Zlib compressed data, default compression, uncompressed size >= 98304
1922524       0x1D55DC        PNG image, 1440 x 900, 8-bit/color RGB, non-interlaced
1922565       0x1D5605        Zlib compressed data, default compression, uncompressed size >= 98304


有两张图片,第二张图offset起始位置为0x1D55DC

用winhex将第二张图抠出来,用stegsolve比较两张图片,做一下异或,发现存在少许差异,差异位置在0x1110~1330附近。在第二张图片保存为bmp位置,抠出对应位置的数据保存为一个文件ccc。将其中的00,01抠出来,再00转化为’0’,01转化为’1’,最后二进制转成字符串即可。

编写py代码:

f=open('ccc','rb')
x=list(f.read())
aa=''.join(str(ord(i)) for i in x if ord(i) in [0,1])
b='%x'%(int(aa,2))
print 'Flag:'+b.decode('hex')
#得到Flag:ISG{E4sY_StEg4n0gR4pHy}
f.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: