简体   繁体   中英

How to write a bash script that executes gdb on a program

I am recreating the buffer overflow from http://www.cis.syr.edu/~wedu/seed/Labs_12.04/Software/Buffer_Overflow/Buffer_Overflow.pdf and I would like to write a bash script that will gdb on my "stack" executable. The script will then make break points and grab the addresses of the begging (p &buffer) and end (p $ebp) of the buffer that the will be passed into./exploit <&buffer, $ebp> as arguments.

When I run my script..

#!/bin/sh
gdb stack
b main
b 14
run
b 23
c
p &buffer
p $ebp

When I use it, gdb is opened on my executable. However, the rest of the script is not executed. I assume this is because gdb creates a new process. I have tried " gdb stack "$$" " to get gdb on the same process as my script, however unsuccessful.

Is what I am trying to do possible?

Edit:

New Script: This correctly outputs the addresses to the command line

#!/bin/sh
gdb stack << 'EOF'
  b main
  run
  b 23
  c
  s
  p &buffer
  p $ebp
  quit
EOF

How do I grab those addresses so I can pass them in as arguments to./exploit?

Following line of my bash file will be..

./exploit <&buffer> <$ebp>

Try

gdb -batch yourfile

as supossed in man gdb .

Or look here for an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM