-1

I am writing a Python to process a log file. The program decrypts a base64 encoded string between two patterns. Whenever I run the code I get "Incorrect Padding Error"

Here is my code

        import base64
        import re

        def find_between_r( s, first, last ):
            try:
                start = s.rindex( first ) + len( first )
                end = s.rindex( last, start )
                return s[start:end]
            except ValueError:
                return ""

        text='192.168.1.23 - - [18/Jun/2015:12:16:12 +0200] "GET /admin/?action=membres&order=QVNDLChzZWxlY3QgKGNhc2UgZmllbGQoY29uY2F0KHN1YnN0cmluZyhiaW4oYXNjaWkoc3Vic3RyaW5nKHBhc3N3b3JkLDE3LDEpKSksMSwxKSxzdWJzdHJpbmcoYmluKGFzY2lpKHN1YnN0cmluZyhwYXNzd29yZCwxNywxKSkpLDIsMSkpLGNvbmNhdChjaGFyKDQ4KSxjaGFyKDQ4KSksY29uY2F0KGNoYXIoNDgpLGNoYXIoNDkpKSxjb25jYXQoY2hhcig0OSksY2hhcig0OCkpLGNvbmNhdChjaGFyKDQ5KSxjaGFyKDQ5KSkpd2hlbiAxIHRoZW4gVFJVRSB3aGVuIDIgdGhlbiBzbGVlcCgyKSB3aGVuIDMgdGhlbiBzbGVlcCg0KSB3aGVuIDQgdGhlbiBzbGVlcCg2KSBlbmQpIGZyb20gbWVtYnJlcyB3aGVyZSBpZD0xKQ%3D%3D HTTP/1.1" 200 1007 "-" "-"'

        result = re.search('order=(.*) H', text)
        t=result.group(1)

        print(base64.b64decode(t))
        #with open("26828869_ch13.txt","rt") as in_file:
        #   for line in in_file:

The image contains the error

mahbuhsj
  • 33
  • 1
  • 6

1 Answers1

1

because this is base 85! not base 64! try this:

import base64
import binascii
import re


def find_between_r(s, first, last):
    try:
        start = s.rindex(first) + len(first)
        end = s.rindex(last, start)
        return s[start:end]
    except ValueError:
        return ""


text = '192.168.1.23 - - [18/Jun/2015:12:16:12 +0200] "GET /admin/?action=membres&order=QVNDLChzZWxlY3QgKGNhc2UgZmllbGQoY29uY2F0KHN1YnN0cmluZyhiaW4oYXNjaWkoc3Vic3RyaW5nKHBhc3N3b3JkLDE3LDEpKSksMSwxKSxzdWJzdHJpbmcoYmluKGFzY2lpKHN1YnN0cmluZyhwYXNzd29yZCwxNywxKSkpLDIsMSkpLGNvbmNhdChjaGFyKDQ4KSxjaGFyKDQ4KSksY29uY2F0KGNoYXIoNDgpLGNoYXIoNDkpKSxjb25jYXQoY2hhcig0OSksY2hhcig0OCkpLGNvbmNhdChjaGFyKDQ5KSxjaGFyKDQ5KSkpd2hlbiAxIHRoZW4gVFJVRSB3aGVuIDIgdGhlbiBzbGVlcCgyKSB3aGVuIDMgdGhlbiBzbGVlcCg0KSB3aGVuIDQgdGhlbiBzbGVlcCg2KSBlbmQpIGZyb20gbWVtYnJlcyB3aGVyZSBpZD0xKQ%3D%3D HTTP/1.1" 200 1007 "-" "-"'

result = re.search('order=(.*) H', text)
t = result.group(1)
print(base64.b85decode(t))
DRPK
  • 2,023
  • 1
  • 14
  • 27
  • when I appended two == to the text file I get the output as b'ASC,(select (case field(concat(substring(bin(ascii(substring(password,17,1))),1,1),substring(bin(ascii(substring(password,17,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)' – mahbuhsj Oct 29 '17 at 19:02
  • if you have a new question, you should ask it on another post. – DRPK Oct 29 '17 at 19:06
  • its part of the same question, adding '==' to the text makes the code work – mahbuhsj Oct 29 '17 at 19:09