SLAE - Extras Flashcards
Opcodes and ASM commands
Accessing memory reference with []
- message db 0xAA, 0xBB, 0xCC, 0xDD <== makes variable message
- mov eax, message <== moves address of message into eax
- mov eax, [message] <== moves value of message into eax
declaring uninitialized data -
What is resb
What is resw
buffer: resb 64 ; reserve 64 bytes
wordvar: resw 1 ; reserve a word
Uninitialized data is placed in the bss segment
Check NASM manual pg. 30
Special tokens -
- What is $
- What is $$
$ - evaluates to the current line
$$ - evaluates to the beginning of the current section
These are used at times to figure out the offset of the current instruction from something else (often)
for example
message: db ‘hello world!’
msglen: equ $-message
So how this works is $ signifies a reference to the beginning of the second line before msglen while message signifies the beginning of the ‘hello world!’ string, so $ - message = ‘len of ‘h-!’
Or jmp $ would create an infinite loop that keep jumping back to the beginning of the section
This is a bit confusing check SLAE module 10 5:57
Check NASM manual pg. 37
TIMES
what does the following lines of code do
(i)
zerobuf: times 64 db 0
(ii)
times 100 movsb
(i)
zerobuf: times 64 db 0
repeats ‘declare byte 0’ 64 times
(ii)
times 100 movsb
instruction where movsb is to be repeated 100 times
What is Little Endian
The lower byte gets stored in lower memory and the higher byte gets stored in higher memory
https: //upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Little-Endian.svg/200px-Little-Endian.svg.png
https: //en.wikipedia.org/wiki/File:Big-Endian.svg
LEA:
1) What does it stand for
2) What does it do
3) Syntax of LEA
4) What is its opcode
1) LEA stands for 'Load Effective Address' 2) It loads a pointer values for example into a register 3) if the variable 'label' is at 0x8049254
LEA EAX, [label]
will make the value of EAX 0x8049254
4)
8D
XCHG:
1) What does it stand for
2) What does it do
3) Syntax of XCHG
4) What is its opcode
1)
Exchange
2)
It swaps values for example in registers
3)
XCHG Register, Register
(swaps values of two registers)
XCHG Register, Memory
(Swaps values of register and memory address)
4) Going to skip for minute due to different registers but makes to come back to
What is MOV
What are its allowed directions
MOV - Responsible for moving register memory and data in the following ways
- Allowed directions
- Between registers
- Memory to register and register to memory
- Immediate data to register
- Immediate data to memory
r/m16 and r/m32 means…
it means it could be taking a value either from a register, or a memory
For example in x86 you can only push and pop r/m16 and r/m32 values on the stack
ie 16 bit and 32 bit
r/m16
push ax
pop bx
r/m32
push eax
pop ecx
What instructions does LEAVE do
LEAVE is equivalent to :
MOV ESP, EBP
POP EBP.
Functions will often start with
PUSH EBP
MOV EBP, ESP
So LEAVE returns things to the state they were in when we initiated the function
When using EBP as a base pointer for a function, what will the offsets from EBP be for
- the return address
- the first parameter
- the first local variable
Represent it as EBP+(number)
* the return address: EBP+4 * the first parameter: EBP+8 * the first local variable: EBP-4
By using a base pointer the return address will always be at ebp+4, the first parameter will always be at ebp+8, and the first local variable will always be at ebp-4. Even as the stack size grows and shrinks those offsets do not change. This also makes it easier for disassemblers because it’s easy to track the parameters and local variables being access throughout the function because their addresses never change.
For example:
0022FEC4 00404016 ASCII “Function 1”
0022FEC8 /0022FEF8 Frame Pointer EBP
0022FECC |00401596 Return Address in main()
0022FED0 |11111111 Argument to function 1
See:
https://practicalmalwareanalysis.com/2012/04/03/all-about-ebp/
What does RETN do
POP EIP???
The stack will onwound by the functions conclusion
LEAVE is equivalent to :
MOV ESP, EBP
POP EBP.
That means the stack should now point to the address just after it was called.
so the
POP EIP
will bring us to the place in program after the function was called and flow will continue
RET pops top of stack into EIP
CMP
TEST
JE [Jump if Equals]
CMP subtracts the operands and sets the flags. Namely, it sets the zero flag if the difference is zero (operands are equal).
TEST sets the zero flag, ZF, when the result of the AND operation is zero. If two operands are equal, their bitwise AND is zero when both are zero. TEST also sets the sign flag, SF, when the most significant bit is set in the result, and the parity flag, PF, when the number of set bits is even.
See here for excellent explanation:
https://reverseengineering.stackexchange.com/a/15185
JE [Jump if Equals] tests the zero flag and jumps if the flag is set. JE is an alias of JZ [Jump if Zero] so the disassembler cannot select one based on the opcode. JE is named such because the zero flag is set if the arguments to CMP are equal.
So,
TEST %eax, %eax
JE 400e77
jumps if the %eax is zero.
How do you easily get the shellcode into assembly instructions. What command on Kali
pipe it into:
| ndisam -u -
For example:
$msfvenom windows -p windows/shell_bind_tcp -f c | ndisasm -u - -p intel
A way to find your shellcode using the hex dump in Immunity
- Copy a part of it into clipboard, lets say:
\xfc\xe8\x82\x00 - Right click on the Hex Dump window and select:
Search for > Binary string
(or ctrl + b) - This will get you the address