我目前正在编写一个编程挑战,我需要从字符串中删除base64文本,解码它然后做更多有趣的事情。
我已经完成了第一步剥离base64文本并将其保存到平面文件,我正在对它进行第二次传递并且我得到填充错误。
print(base64.b64decode(next))
File "/usr/lib/python2.7/base64.py", line 78, in b64decode
raise TypeError(msg)
TypeError: Incorrect padding
现在我写的代码非常简单
o.write(str(i) + ". "+base64.b64decode(next)+"\n\r")
并且前36个字符串正确解码但37,38等不正确。以下是两个例子
第36行: QVNDLChzZWxlY3QgKGNhc2UgZmllbGQoY29uY2F0KHN1YnN0cmluZyhiaW4oYXNjaWkoc3Vic3RyaW5nKHBhc3N3b3JkLDksMSkpKSw3LDEpKSxjaGFyKDQ4KSxjaGFyKDQ5KSkgd2hlbiAxIHRoZW4gc2xlZXAoMikgd2hlbiAyIHRoZW4gc2xlZXAoNCkgIGVuZCkgZnJvbSBtZW1icmVzIHdoZXJlIGlkPTEp =
解码为36。
ASC,(select (case field(concat(substring(bin(ascii(substring(password,9,1))),7,1)),char(48),char(49)) when 1 then sleep(2) when 2 then sleep(4) end) from membres where id=1)
第37行: QVNDLChzZWxlY3QgKGNhc2UgZmllbGQoY29uY2F0KHN1YnN0cmluZyhiaW4oYXNjaWkoc3Vic3RyaW5nKHBhc3N3b3JkLDEwLDEpKSksMSwxKSxzdWJzdHJpbmcoYmluKGFzY2lpKHN1YnN0cmluZyhwYXNzd29yZCwxMCwxKSkpLDIsMSkpLGNvbmNhdChjaGFyKDQ4KSxjaGFyKDQ4KSksY29uY2F0KGNoYXIoNDgpLGNoYXIoNDkpKSxjb25jYXQoY2hhcig0OSksY2hhcig0OCkpLGNvbmNhdChjaGFyKDQ5KSxjaGFyKDQ5KSkpd2hlbiAxIHRoZW4gVFJVRSB3aGVuIDIgdGhlbiBzbGVlcCgyKSB3aGVuIDMgdGhlbiBzbGVlcCg0KSB3aGVuIDQgdGhlbiBzbGVlcCg2KSBlbmQpIGZyb20gbWVtYnJlcyB3aGVyZSBpZD0xKQ =
我在一个在线base64解码器(base64decode.org)中测试了字符串37,它可以正常工作
ASC,(select (case field(concat(substring(bin(ascii(substring(password,10,1))),1,1),substring(bin(ascii(substring(password,10,1))),2,1)),concat(char(48),char(48)),concat(char(48),char(49)),concat(char(49),char(48)),concat(char(49),char(49)))when 1 then TRUE when 2 then sleep(2) when 3 then sleep(4) when 4 then sleep(6) end) from membres where id=1)
有什么明显的事我做错了吗?
答案 0 :(得分:3)
好吧,填充
QVNDLChzZWxlY3QgKGNhc2UgZmllbGQoY29uY2F0KHN1YnN0cmluZyhiaW4oYXNjaWkoc3Vic3RyaW5nKHBhc3N3b3JkLDEwLDEpKSksMSwxKSxzdWJzdHJpbmcoYmluKGFzY2lpKHN1YnN0cmluZyhwYXNzd29yZCwxMCwxKSkpLDIsMSkpLGNvbmNhdChjaGFyKDQ4KSxjaGFyKDQ4KSksY29uY2F0KGNoYXIoNDgpLGNoYXIoNDkpKSxjb25jYXQoY2hhcig0OSksY2hhcig0OCkpLGNvbmNhdChjaGFyKDQ5KSxjaGFyKDQ5KSkpd2hlbiAxIHRoZW4gVFJVRSB3aGVuIDIgdGhlbiBzbGVlcCgyKSB3aGVuIDMgdGhlbiBzbGVlcCg0KSB3aGVuIDQgdGhlbiBzbGVlcCg2KSBlbmQpIGZyb20gbWVtYnJlcyB3aGVyZSBpZD0xKQ =
错误,因为它的长度为467,不能被4整除,而是Base64 encodes 3 source octets as 4 symbols。这只是some Base64 implementations don't care about padding(显然包括你使用的在线工具),而其他实现(显然包括Python)确实关心。
QVNDLChzZWxlY3QgKGNhc2UgZmllbGQoY29uY2F0KHN1YnN0cmluZyhiaW4oYXNjaWkoc3Vic3RyaW5nKHBhc3N3b3JkLDEwLDEpKSksMSwxKSxzdWJzdHJpbmcoYmluKGFzY2lpKHN1YnN0cmluZyhwYXNzd29yZCwxMCwxKSkpLDIsMSkpLGNvbmNhdChjaGFyKDQ4KSxjaGFyKDQ4KSksY29uY2F0KGNoYXIoNDgpLGNoYXIoNDkpKSxjb25jYXQoY2hhcig0OSksY2hhcig0OCkpLGNvbmNhdChjaGFyKDQ5KSxjaGFyKDQ5KSkpd2hlbiAxIHRoZW4gVFJVRSB3aGVuIDIgdGhlbiBzbGVlcCgyKSB3aGVuIDMgdGhlbiBzbGVlcCg0KSB3aGVuIDQgdGhlbiBzbGVlcCg2KSBlbmQpIGZyb20gbWVtYnJlcyB3aGVyZSBpZD0xKQ = <强> = 强>
作品。