📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Brainstorms - General  >>  x86 reference or mini-assembler?

Topic created on: June 27, 2005 20:32 CDT by ryanlrussell .

As a learning exercise, I was writing some Windows x86 shellcode by hand.  This ended up being extraordinarily slow.  Mostly because I don't have a good reference for what the hex values for various instructions will be.  

Does anyone have a good reference for this, or (ideally) a mini-assembler?

For example, I'd like to be able to put in:
mov [EBP], AL
and have it spit out the appropriate hex values, or tell me that's not a valid instruction.  By "mini-assembler", I mean something that can do a quick conversion like this, with no context, and not trying to produce a working collection of code.

I have (of course) IDA Pro and Ollydbg, if there's such a function built into those, or maybe a plugin, and I just don't know it.

If I can't have such a util, does anyone have a good reference or cheat sheet that can be used to look up hex values by mnemonic?  I have a few Intel assembly books, but I find those to be unsuitably terse for this purpose.

  pedram     June 27, 2005 21:08.57 CDT
Well within OllyDbg you could just attach to any process, hit the assemble command (space bar) and start entering instructions. It would be nice to have a quick reference for this though. So perhaps I'll build a small webapp around the ever so excellent libdasm disassembler and put it in the reference library.

Regarding a good reference. I find myself constant referring to this windows .hlp reference:

Intel Hex Opcodes and Mnemonics

  ryanlrussell     June 27, 2005 22:05.15 CDT
Ah, both great, thanks!

The .hlp file is handy, and the Assemble function in Ollydbg is just about perfect.

  quig   June 27, 2005 23:07.41 CDT
I ran into a similar need when developing quick patchs and found this along the way

http://sandsprite.com/CodeStuff/cavewriter.jpg

Lets you asm small bits for whatever va you enter
and use the targets existing IAT for API calls.

http://sandsprite.com/CodeStuff/cavewriter.zip

  ryanlrussell     June 28, 2005 00:07.20 CDT
Impressive tool, quig!  Took me a few minutes to figure out the UI.  I had to actually read the instructions. :)

That's a nice way to assemble up a quick bit of code, and using the imports from the target is a useful feature as well.

  JCRoberts     June 28, 2005 01:26.15 CDT
Ryan,
I know your question was x86 specific but there are tons of other systems out there. A person you may want to ask, is Fyodor (of snort fame, rather than Fyodor of nmap fame). I know he did some work generating shell code for a vast number of archs. If you need a contact address for him, send me an email.

Also if you want to build your own tool, the gnu assembler sources should also have the opcode to mnemonic mappings you need.

  Kayaker     June 28, 2005 12:04.50 CDT
Hi

HIEW would probably work, but there's also a handy little util that is suitable just for this purpose, RTA by Squidge

http://www.wasm.ru/baixado.php?mode=tool&id=181

Regards,
Kayaker

  ryanlrussell     June 28, 2005 12:06.23 CDT
JCR: Yup, I just figured such a beast was most likely to exist for x86 if anything, and that happened to be the task at hand.  Such a tool that did various architectures would be cool as well, of course.

I might look into some of he various shellcode generators, as you mentioned.  Spoonm also gave an interesting presentation along those lines at REcon, and I believe some of Dave Aitel's tools will compile shellcode as well.

Since I was writing shellcode, I did have some minor restrictions on the characters I could use.  In particular, the overflow was passed as a command-line argument, so any kind of whitespace or line terminator (and of course NULL) couldn't be used.

I suppose if one wanted to build the ideal shellcode calculator applet, you would have a radio button for the processor, and have a set of settings for what characters were not allowed.  Then you would type in some assembly or maybe some pseudo code or slightly higher-level language, and the calculator would spit out the assembly and hex.  One could make it smart enough to be able to suggest an alternate expression with the same effect, designed to fit in your character restrictions, or maybe to optimize for size.

If I'm going to keep a wishlist, I might as well do it right. :)

  ryanlrussell     June 28, 2005 12:31.34 CDT
Kayaker: RTA is pretty much exactly what I wanted, thanks!

HIEW doesn't seem to want to run on my machine.

  nico     June 28, 2005 14:57.08 CDT
I personally use RTA myself. it is pretty handy.

Else, when i need big chunks of assembly, I have done a little TASM project, where i write whatever i need to assemble. I assemble and link it. Then i execute it, and i have a simple CreateFileA/WriteFile to extract the shellcode or whatever piece of code i have there, into a bin file.
Then it would take a few minutes to write an utility to create C, Assembly, delphi, or whatever language arrays, ready to be placed into your sploit for instance.

While this is not the best way to do it (i don't use nasm much), if you have big code to write, ie longer than usual shellcodes, it is pretty handy.

  anonymouse     June 29, 2005 03:48.04 CDT
well sometime back i did kinda what nico suggested  using masm
maybe its usefull
i created a bat file with this content

@echo off
ml /c /coff /nologo whatever.asm
dumpbin /rawdata:bytes whatever.obj /out:shellcode.txt
edit shellcode.txt


now if i have an asm file named whatever.asm like this
[code]
.386
.model flat, stdcall
option casemap:none
bamba PROTO
gimba PROTO :DWORD
.code
start:
push 0
push 401020
push 401040
push 0
call bamba
invoke gimba,9


bamba proc
nop
nop
nop
nop
nop
nop
nop
nop
ret
bamba endp

gimba proc handle
push handle
push 0
nop
nop
push 87h
ret
gimba endp
end start

and run the bat
you will get a shellcode.txt like this

[code]
Dump of file t.obj

File Type: COFF OBJECT

RAW DATA #1
  00000000: 6A 00 68 7C 1E 06 00 68 90 1E 06 00 6A 00 E8 07  j.h|...h....j.

  anonymouse     June 29, 2005 11:00.56 CDT
btw pedram as hoglund suggests a way to edit posts would be fine too :)

i wanted to add this saved link to my post but i am forced to create a new one
a nice article about creating shell codes
http://www.linuxgazette.com/node/9166

  inFinie     July 4, 2005 04:15.24 CDT
mnemonix.exe is in masm32 package, www.movsd.com. Maybe you may get it seperately. it is a listbox of mnemonics.

  dennis     July 4, 2005 04:40.09 CDT
as far as i know (haven't had a look at the most recent version), it is not a very complete list.

  daveaitel     July 6, 2005 17:09.47 CDT
MOSDEF is one solution. For example CANVAS_ME/MOSDEF/mosdef.py -a "mov %al, (%ebp)" will tell you the answer to your question. :>. If you're having a really good time, you can call assembleEx(code,arch) and have it tell you a long list of meta-data attached to each bit. Assembling jmps is harder that it seems...


Should I make MOSDEF's assembler a web service? :>

  ryanlrussell     July 6, 2005 18:23.29 CDT
I haven't actually gotten around to looking at mosdef yet, I should.  But yes, if it can be used as a library easily, then it might be quite suitable.  It could be especially nice because of the multi-platform support.

  cseagle     July 18, 2005 14:07.16 CDT
If you have cygwin and nasm installed, you could try the following:

#!/bin/sh
while read; do
   echo "USE32" > /tmp/assemble
   echo $REPLY >> /tmp/assemble
   nasm -f bin -o /tmp/assemble.bin /tmp/assemble
   if [ -f /tmp/assemble.bin ]; then
      od -A x -t x1 /tmp/assemble.bin | head -n 1 | cut -c 8-
   fi;
done
rm -rf /tmp/assemble
rm -rf /tmp/assemble.bin

Which in interactive and looks like this when run:

# ./assemble.sh
mov [ebp],eax
89 45 00
mov [ebp],al
88 45 00
jmp eax
ff e0
xor ecx,ecx
31 c9
nop
90

Alternatively you could use cat to pipe a larger file through it, though you might as well use nasm directly on the file in that case.

Chris

  cseagle     July 18, 2005 17:02.52 CDT
Apologies for replying to myself.  Pedram let me know of a cross platform problem and I think the following is a bit better:

#!/bin/sh
#cygwin users probably need /usr/bin/sh above
while read x; do
   echo "USE32" > /tmp/assemble
   echo $x >> /tmp/assemble
   nasm -f bin -o /tmp/assemble.bin /tmp/assemble
   if [ -f /tmp/assemble.bin ]; then
      od -A x -t x1 /tmp/assemble.bin | head -n 1 | cut -c 8-
   fi;
done
rm -rf /tmp/assemble
rm -rf /tmp/assemble.bin

Chris

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit