plaidctf2015 uncorrupt png

Source: Internet
Author: User

The execution time of the code is very long, very embarrassing!

Reference the code of the https://13c5.wordpress.com/2015/04/20/plaidctf-2015-png-uncorrupt/

Through this topic, also to the PNG file format more in-depth understanding!

The premise of using this code is to change the 0x0a inside PNG signature to 0x0d0a

1  fromItertools Import Combinations2 Import Binascii3 Import OS4 5 6 def find_all (source,aim):7start=08       whileTrue:9start=Source.find (Aim,start)Ten           ifstart==-1: One                return A           yieldStart -Start + =Len (AIM) -  the def repair (SOURCE,AIM,FILEDES,NUM,CRC): -Matchlist=list (Find_all (source,'\x0a')) -  -       forSubnetinchcombinations (matchlist,num): +subnet=sorted (subnet) -temp="' +           if(num==3): Atemp=source[:subnet[0]]+'\x0d\x0a'+source[subnet[0]+1: subnet[1]]+'\x0d\x0a'+source[subnet[1]+1: subnet[2]]+'\x0d\x0a'+source[subnet[2]+1:] at           if(num==2): -temp=source[:subnet[0]]+'\x0d\x0a'+source[subnet[0]+1: subnet[1]]+'\x0d\x0a'+source[subnet[1]+1:] -           if(num==1): -temp=source[:subnet[0]]+'\x0d\x0a'+source[subnet[0]+1:] -           if "%08x"% (BINASCII.CRC32 (temp) &0xFFFFFFFF)==CRC: - filedes.write (temp) in Filedes.write (Binascii.a2b_hex (CRC)) - Filedes.flush () toPrint"Success" +                 Break; -Print"fail" the  *Uncfile=open ("Corrupt_735acee15fa4f3be8ecd0c6bcf294fd4.png","RB") $Cocfile=open ("Correct.png","WB")Panax Notoginseng #first Write -Correct=uncfile.read (0x6d) the Cocfile.write (correct) + Cocfile.flush () A  theCorrect=uncfile.read (0x4) #length + Cocfile.write (correct) - Cocfile.flush () $  $Uncorrect=uncfile.read (0x20000-0x1+0x4) -Crc=uncfile.read (0x4) -Crc=Binascii.hexlify (CRC) the Print CRC -Repair (Uncorrect,'\x0a', Cocfile,1, CRC) #1Wuyi #second Write theCorrect=uncfile.read (0x4) #length - Cocfile.write (correct) Wu Cocfile.flush () -Uncorrect=uncfile.read (0x20000-0x3+0x4) AboutCrc=uncfile.read (0x4) $Crc=Binascii.hexlify (CRC) - Print CRC -Repair (Uncorrect,'\x0a', Cocfile,3, CRC) #2 - #third Write ACorrect=uncfile.read (0x4) #length + Cocfile.write (correct) the Cocfile.flush () -Uncorrect=uncfile.read (0x20000-0x1+0x4) $Crc=uncfile.read (0x4) theCrc=Binascii.hexlify (CRC) the Print CRC theRepair (Uncorrect,'\x0a', Cocfile,1, CRC) #3 the #fourth Write -Correct=uncfile.read (0x4+0x4+0x20000+0x4) in Cocfile.write (correct) the Cocfile.flush () the #fifth Write AboutCorrect=uncfile.read (0x4) #length the Cocfile.write (correct) the Cocfile.flush () theUncorrect=uncfile.read (0x20000-0x3+0x4) +Crc=uncfile.read (0x4) -Crc=Binascii.hexlify (CRC) the Print CRCBayiRepair (Uncorrect,'\x0a', Cocfile,3, CRC) #4 the #6th theCorrect=uncfile.read (0x4) #length - Cocfile.write (correct) - Cocfile.flush () theUncorrect=uncfile.read (0x20000-0x1+0x4) theCrc=uncfile.read (0x4) theCrc=Binascii.hexlify (CRC) the Print CRC -Repair (Uncorrect,'\x0a', Cocfile,1, CRC) #5 the #7th theCorrect=uncfile.read (0x4) the Cocfile.write (correct)94 Cocfile.flush () theUncorrect=uncfile.read (0x20000-0x2+0x4) theCrc=uncfile.read (0x4) theCrc=Binascii.hexlify (CRC)98 Print CRC AboutRepair (Uncorrect,'\x0a', Cocfile,2, CRC) #6 - #8th101Correct=uncfile.read (0x4+0x4+0x20000+0x4)102 Cocfile.write (correct)103 Cocfile.flush ()104 #9th theCorrect=uncfile.read (0x4)106 Cocfile.write (correct)107 Cocfile.flush ()108Uncorrect=uncfile.read (0x20000-0x1+0x4)109Crc=uncfile.read (0x4) theCrc=Binascii.hexlify (CRC)111 Print CRC theRepair (Uncorrect,'\x0a', Cocfile,1, CRC) #7113 #10th theCorrect=uncfile.read (0x4+0x4+0x216f) the Cocfile.write (correct) the Cocfile.flush ()117 118 uncfile.close ()119Cocfile.close ()

  

Results:

Reference documents:

http://blog.csdn.net/gogor/article/details/5265710

Http://www.libpng.org/pub/png/apps/pngcheck.html

Http://www.libpng.org/pub/png/book/chapter08.html

http://stackoverflow.com/questions/27238021/png-images-not-loaded

https://13c5.wordpress.com/2015/04/20/plaidctf-2015-png-uncorrupt/

plaidctf2015 uncorrupt png

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.