for i in $(objdump -d binary -M intel |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo

Get shellcode of the binary using objdump

Anyone can make the command smaller & easier? :)
Sample Output
\x31\xc0\x31\xdb\x31\xd2\xb0\x04\xb3\x01\x68\x65\x72\x65\x0a\x68\x48\x69\x54\x68\x89\xe1\xb2\x08\xcd\x80\x31\xdb\xb0\x01\xcd\x80

3
By: arno
2013-04-09 09:44:31

These Might Interest You

  • The options -b binary and -m are needed for disassembling raw machine code when it is not part of a full binary executable with proper headers. Show Sample Output


    2
    objdump -b binary -m i386 -D shellcode.bin
    recursiverse · 2010-04-27 11:11:36 2
  • Tired copy paste to get opcode from objdump huh ? Get more @ http://gunslingerc0de.wordpress.com Show Sample Output


    4
    objdump -d ./PROGRAM|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'
    gunslinger_ · 2010-07-11 15:44:48 4

  • 1
    hexdump -v -e '"\\""x" 1/1 "%02x" ""' <bin_file>
    damncool · 2010-12-31 15:23:07 0
  • This one liner takes the shell code that you can grab off of the web and disassemble it into readable assembly so you can validate the code does what it says, before using it. The shell code in the above example is from http://www.shell-storm.org/shellcode/files/shellcode-623.php You can replace "-s intel" with "-s att" to get AT&T format disassembly. Show Sample Output


    13
    echo -ne "<shellcode>" | x86dis -e 0 -s intel
    dsearle · 2010-06-12 08:08:13 0
  • bvi is your vi for binary editing. If your system does not have it, you can get it from http://bvi.sourceforge.net/


    -3
    bvi [binary-file]
    haivu · 2009-03-24 15:30:50 0
  • If you should happen to find yourself needing some binary numbers, this is a quickie way of doing it. If you need more digits, just add more "{0..1}" sequences for each digit you need. You can assign them to an array, too, and access them by their decimal equivalent for a quickie binary to decimal conversion (for larger values it's probably better to use another method). Note: this works in bash, ksh and zsh. For zsh, though, you'll need to issue a setopt KSH_ARRAYS to make the array zero-based. binary=({0..1}{0..1}{0..1}{0..1}) echo ${binary[9]} Show Sample Output


    17
    echo {0..1}{0..1}{0..1}{0..1}
    dennisw · 2009-06-23 17:30:20 5

What Others Think

Even shorter: for i in $(objdump -d helloworld |grep "^ " |cut -f2); do echo -n '\x'$i; done; echo
arno · 266 weeks and 3 days ago
Great! The smallest command to extract shellcode that I know!
geyslan · 266 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: