기타 CTF 문제 (메모)

11012 단어 ctf
1. ISG 2014 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), 0x 20) FROM isg. flags ORDER BY value LIMIT 0, 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+"
"
) 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
"
%(lastpos,chr(lastchar),m1.group(1))) flags+=chr(lastchar+1) # , > , +1 else: fw.write("%d:%c
"
%(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: 흥, 그림 을 주 었 는데 빈 워 크 가 두 장의 그림 을 발견 했다.
@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()

좋은 웹페이지 즐겨찾기