PRACTICAL EXERCISES

These are hands-on challenges presented at the end of each module to reinforce newly learned concepts. These tasks require learners to immediately apply techniques discussed in the lesson, ensuring they understand how the theory translates into real-world offensive or defensive operations. By engaging directly with simulated environments, users build muscle memory, identify gaps in understanding, and develop confidence in executing the skills before moving on.

ASSEMBLY LANGUAGE

In the below 'Hello World' example, which Assembly instruction will '00001111 00000101' execute?
//Hello World Assembly Instruction
mov rax, 1
mov rdi, 1
mov rsi, message
mov rdx, 12
syscall

mov rax, 60
mov rdi, 0
syscall
//Hello World Hexadecimal Machine Code Representation
48 c7 c0 01
48 c7 c7 01
48 8b 34 25
48 c7 c2 0c
0f 05

48 c7 c0 3c
48 c7 c7 00
0f 05
//Hello World Binary Machine Code Representation
01001000 11000111 11000000 00000001
01001000 11000111 11000111 00000001
01001000 10001011 00110100 00100101
01001000 11000111 11000010 00001101 
00001111 00000101

01001000 11000111 11000000 00111100 
01001000 11000111 11000111 00000000 
00001111 00000101

REGISTERS, ADDRESSES & DATA TYPES

What is the 8-bit register for 'rdi'?
Description                  64-bit   32-bit   16-bit   8-bit
----------------------------------------------------------------
Data / Argument Registers
Syscall Number / Return val  rax      eax      ax       al
Callee Saved                 rbx      ebx      bx       bl
1st arg - Destination operand rdi     edi      di       dil
2nd arg - Source operand     rsi      esi      si       sil
3rd arg                      rdx      edx      dx       dl
4th arg - Loop counter       rcx      ecx      cx       cl
5th arg                      r8       r8d      r8w      r8b
6th arg                      r9       r9d      r9w      r9b

Pointer Registers
Base Stack Pointer           rbp      ebp      bp       bpl
Current / Top Stack Pointer  rsp      esp      sp       spl
Instruction Pointer (call)   rip      eip      ip       ipl

ASSEMBLING & DISASSEMBLING

Download the attached file and disassemble it to find the flag
//TRIAGE
root@htb:~$ curl -O https://academy.hackthebox.com/storage/modules/85/disasm.zip
root@htb:~$ ls
 disasm.zip
root@htb:~$ unzip disasm.zip 
 Archive:  disasm.zip
  inflating: disasm 

root@htb:~$ file disasm
 disasm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

root@htb:~$ strings disasm
 HBT{d154553m811n9_81n42135_2_f1nd_53c2375}
 disasm.s
 message
 length
 __bss_start
 _edata
 _end
 .symtab
 .strtab
 .shstrtab
 .text
 .data
root@htb:~$ objdump -M intel -d disasm
 disasm:     file format elf64-x86-64
 Disassembly of section .text:
 0000000000401000 <_start>:
  401000:	48 b8 00 20 40 00 00 	movabs rax,0x402000
  401007:	00 00 00 
  40100a:	48 31 c0             	xor    rax,rax
  40100d:	b8 3c 00 00 00       	mov    eax,0x3c
  401012:	bf 00 00 00 00       	mov    edi,0x0
  401017:	0f 05                	syscall


root@htb:~$ objdump -M intel -sj .data disasm
 disasm:     file format elf64-x86-64

 Contents of section .data:
  402000 4842547b 64313534 3535336d 3831316e  HBT{d154553m811n
  402010 395f3831 6e343231 33355f32 5f66316e  9_81n42135_2_f1n
  402020 645f3533 63323337 357d               d_53c2375} 

DEBUGGING WITH GDB

Download the attached file, and find the hex value in 'rax' when we reach the instruction at <_start+16>?

DATA MOVEMENT

Add an instruction at the end of the attached code to move the value in "rsp" to "rax". What is the hex value of "rax" at the end of program execution?

ARITHMETIC INSTRUCTIONS

Add an instruction to the end of the attached code to "xor" "rbx" with "15". What is the hex value of 'rbx' at the end?

LOOPS

Edit the attached assembly code to loop the "loop" label 5 times. What is the hex value of "rax" by the end?

UNCONDITIONAL BRANCHING

Try to jump to "func" before "loop loop". What is the hex value of "rbx" at the end?

CONDITIONAL BRANCHING

The attached assembly code loops forever. Try to modify (mov rax, 5) to make it not loop. What hex value prevents the loop?

USING THE STACK

Debug the attached binary to find the flag being pushed to the stack

SYSCALLS

What is the syscall number of "execve"?

How many arguments does "execve" take?

PROCEDURES

Try assembling and debugging the above code, and note how "call" and "ret" store and retrieve "rip" on the stack. What is the address at the top of the stack after entering "Exit"? (6-digit hex 0xaddress, without zeroes)

FUNCTIONS

Try to fix the Stack Alignment in "print", so it does not crash, and prints "Its Aligned!". How much boundary was needed to be added? "write a number"

LIBC FUNCTIONS

The current string format we are using only allows numbers up to 2 billion. What format can we use to allow up to 3 billion? "Check length modifiers in the 'printf' man page"

SHELLCODES

Run the "Exercise Shellcode" to get the flag.

SHELLCODING TOOLS

The above server simulates an exploitable server you can execute shellcodes on. Use one of the tools to generate a shellcode that prints the content of '/flag.txt', then connect to the server with "nc SERVER_IP PORT" to send the shellcode.

Last updated