ctf之AWD(4)_重写菜刀

ctf之AWD(4)_重写菜刀convertToHex#convertToHex : 读取二进制文件并转成字符串,#将字母转成大写,并按字节对齐, python3读取 二进制 文件要将 0x 去掉0x10之前的ascii去掉`0x`后要按字节对齐,在字母前面添加'0'eg: ord('\n') = 10 hex(10) = '0xa' 对齐后: '0A'将代码保存为att...
摘要由CSDN通过智能技术生成

ctf之AWD(4)_重写菜刀

convertToHex

#convertToHex : 读取二进制文件并转成字符串,
#将字母转成大写,并按字节对齐, python3读取 二进制 文件要将 0x 去掉
0x10之前的ascii去掉`0x`后要按字节对齐,在字母前面添加'0'
eg:    ord('\n') = 10   hex(10) = '0xa'  对齐后: '0A'

将代码保存为attack_tool.py 有更好的算法请评论

#####    attack_tool.py    #####
#coding:utf-8
'''
f = open(file,'rt')
newline = '\r\n'
rt : windpws text mode
unix 换行 \n
windows 换行 \r\n    \r\n  <-rt ->  \n
CRLF
Carriage-Return Line-Feed 回车换行
回车(CR, ASCII 13,0D , \r)
换行(LF, ASCII 10,0A, \n)
post:url_encode, data:hex(ascii)
%40:@    %01:SOH    %28:(    %29:)
'''


import string

def convertToHex(infile):
    try:
        out = ''
        f = open(infile,'rb')
        i = 0
        while 1:
            c = f.read(1)    #bytes
            i = i + 1
            if not c:
                break
            #out += hex(ord(c))[2:]    0xff -> FF
            if ord(c) <= 15:
                tmp_str = hex(ord(c))[2:]
                for j in tmp_str:
                    if j in string.ascii_lowercase:
                        out += '0'
                        out += chr(ord(j) - 32)
                    else:
                        out += '0'
                        out += j
            else:
                tmp_str = hex(ord(c))[2:]
                for j in tmp_str:
                    if j in string.ascii_lowercase:
                        out += chr(ord(j) - 32)
                        #print(str(i) + " : " + j + " : " + out)
                    else:
                        out += j
                        #print(str(i) + " : " + j + " : " + out)
            #tmp_str = hex(ord(c))[2:]    #ff
            #tmp_STR = chr(ord(tmp_str)-32)
            # hex(ord('\n'))     '0xa'
            #'0xa'.split('0x') =  ['','a']
            #print(str(i) + ' : ' + out)
        f.close()
        return out
    except Exception as e:
        print('打开文件失败:' + str(e))
        return ''

if __name__ == '__main__':
    infile = 'd:/test.txt'
    strs = convertToHex(infile)
    print(strs)
    print(len(strs))        #1950008
    # f = open('d:/a.txt','w')
    # f.write(strs)
    # f.close()
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值