0

I am practicing Buffer Overflow exploits, and I am following this website. My code looks like this:

# Run the program, waits until it sees ':' (end of prompt), send our format strings, then prints 
# the output. The last line ensures that we don't kill the process
#!/usr/bin/env python  


from pwn import *


io = process('./00')
print(io.recvregex(b':'))  # read untill we get the prompt

io.sendline(b'%p,%p,%p')
io.recvline()
print(io.recvline())

io.sendline(cyclic(50))  # pwntools cyclic generates a 50 char pattern to send as input
io.wait()

core = io.corefile  # pwntools pulls core dump to extract needed values
stack = core.rsp

info('rsp = %#x', stack)
pattern = core.read(stack, 4)
rip_offset = cyclic_find(pattern)

info('rip offset is %d', rip_offsett)
io.interactive()    # interactive() lets us communicate with the program through keyboard

Unfortunatley, I am unable to run it. This is the output I get:

m@m-VirtualBox:~/Documents$ ./pwn.py
from: can't read /var/mail/pwn
./pwn.py: line 7: syntax error near unexpected token `('
./pwn.py: line 7: `io = process('./00')'

I have tried looking at this question for answers, but adding more quotation marks did not solve it, neither did adding the line #!/usr/bin/env python at the top of the .py-file (like they suggested here and here) How do I fix this?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Mampenda
  • 661
  • 4
  • 21
  • 2
    The solution is to add the "shebang" line (`#!/usr/bin/env python`). Your script is being interpreted as a bash script, not a Python script. If that didn't fix it, then you didn't do it correctly. Note that the shebang line MUST BE THE FIRST LINE. You might try typing `python pwn.py` to prove that. – Tim Roberts Sep 20 '22 at 16:46
  • 2
    As a second note, you cannot give your own file the same name as a standard module. When you do `from pwn import *`, Python is going to use YOUR file instead of the module. You need to change your file name. – Tim Roberts Sep 20 '22 at 16:47
  • I changed the name of my program, but I still get the same error... – Mampenda Sep 20 '22 at 16:56
  • 1
    Run the script with `python scriptname.py` rather than `./scriptname.py` – Barmar Sep 20 '22 at 17:00
  • 2
    "Top" means "first line". If you put the shebang anywhere else, it won't work. – wjandrea Sep 20 '22 at 17:09
  • Right. The first line BEFORE any comments. The first two characters in the file must be `'#'` and `'!'`. That's what the Linux kernel looks for to figure out what program runs this file. – Tim Roberts Sep 20 '22 at 22:20

0 Answers0