zoukankan      html  css  js  c++  java
  • 一道逆向出题笔记

      因为我菜,没人找过我出题。突然有个师傅找我出题我还一阵受宠若惊!

      我说pwn题放一放,因为我也是菜鸡。。。我可以试着出一道逆向。然后逆向题目就诞生了!

     1 def verification():
     2     part1 = 'flag{'
     3     part2 = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
     4     part3 = '}'
     5     tmp = ''
     6     part2_1 = part2[:7]
     7     part2_2 = part2[7:20]
     8     part2_3 = part2[20:]
     9     for i in range(len(part2_1)):
    10         tmp += chr(ord(part2_1[i])+1)
    11 
    12     for i in range(len(part2_2)):
    13         tmp += chr(ord(part2_2[i])+0)
    14 
    15     for i in range(len(part2_3)):
    16         tmp += chr(ord(part2_3[i])-1)
    17 
    18     ciphertext = '''M2gf`2t_short_y0u_nedc^Oxsg/m'''
    19     true_flag = part1 + part2 + part3
    20 
    21 def story():
    22     print('One day, after the rain, you were in front of the window and looked at the beautiful scenery outside. You have a girlfriend in your heart. Does she have an umbrella? Will she be cold? Did she eat? Will she be in a bad mood? how old is she? What is her name? Oh, thinking of tears falling out of contention. At this time, you received a letter from your distant buddy.')
    23     print(r'"I finally became the person I hated the most!"')
    24     print(r'You comfort: "Hahaha, everyone is like this, do not be sad. Who do you hate most when you were young?"')
    25     print(r'"Rich people"')
    26     print(r'At this time, your heart is more sad, but there is always a voice echoing in your mind "pyinstaller! Pyinstaller! Pyinstaller!"')
    27     print('py is your girlfriend!')
    28 
    29 def check():
    30     ysr = input()
    31     if(ysr[:5]=='flag{' and ysr[-1:]=='}'):
    32         print('Good!!!')
    33         print('But!!!Not necessarily right!')
    34     else:
    35         print('Flag_is_wrong!')
    36 if __name__ == '__main__':
    37     story()
    38     print("Please enter flag:")
    39     check()
    40     input()

      python的源码是这个,考点是想考pyinstaller反编译!

      pyinstaller是一个库文件,可以将py文件打包成exe文件。

      命令如下:

      pyinstaller -F filename.py

      其中-F是参数,

      这样我就把py打包成了exe,这个就是题目就可以当作附件发出去了。但是我们应该怎么反编译呢?

      反编译需要用到这个脚本pyinstxtractor.py,把exe文件和脚本放在同一目录,执行命令:

      同目录下出现一个文件夹:filename_extracted,点进去就可以看到反编译出来的一些东西了。

      各种引用的库文件呀,外部代码呀都在里面。

      对于做题,我们要关心两个文件:一个是filename,一个是struct。

      其实filename这个文件就是我们可以看到代码的pyc格式的文件,但是由于脚本不够完善,需要我们添加一个文件头。文件头由pyc特有的文件头和时间戳组成。这里我们具体看一下。

      文件头其实是会由于pyinstaller的版本变化而变化,我们需要复制struct的文件头,e3前面的都需要复制。

      我在这里新建了一个空白文件,先把文件头扔进去。再把filename那个文件的16进制全部复制扔进去!

      再说一遍,第一部分取自struct的文件头,第二部分是反编译出来的file的16进制格式的数据。然后保存成pyc格式的文件。

      到了这一步,还需要反编译一次,就是pyc还原py。有网站可以直接反编译:https://tool.lu/pyc/

      也有库可以反编译,叫做uncomyle6

       命令很简单,然后我们打开py文件看看:

      几乎一点错误都没有,完全的和源码一样。

      拿到源码,稍微读一读,随便写个小脚本就可以解出flag了,这里就不演示了!

      其实pyinstaller是可以将弄成pyd格式防破解的,由于是py逆向入门,就不搞那么复杂了。(主要是我菜的不会)

      感觉还是学到了一些东西的,记录一下!

  • 相关阅读:
    log4net 无法输出日志,跟踪发现IsErrorEnabled等,都是Flase
    jquery load加载不了内容
    数据库中的表还是一定要建索引
    最近的项目中用到读卡器,用的华视身份证阅读器,附上SDK使用手册
    背景自动滚动
    理解JavaScript函数(函数和对象的区别和联系)
    代码运行框
    ie8以ie7方式解析
    js开发工具集
    cssZip
  • 原文地址:https://www.cnblogs.com/bhxdn/p/12770744.html
Copyright © 2011-2022 走看看