Differences

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

Link to this comparison view

isc:labs:05 [2024/04/02 12:16]
florin.stancu [00. Setup]
isc:labs:05 [2024/11/04 10:43] (current)
florin.stancu
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]],​ use the **m1.medium** flavor for 1.5GB of RAM (required by ''​pwndbg''​ :(( ).
  
-  ​* **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 not using the OpenStack VM**:
-  * **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 ====+  * Install the 32-bit **libc** and **gcc-multilib** packages: <​code>​ 
 +sudo apt install libc6-dev-i386 gcc-multilib 
 +</​code>​ 
 +  * Install the PwnDbg plugin: <​code>​ 
 +git clone https://​github.com/​pwndbg/​pwndbg 
 +cd pwndbg 
 +./​setup.sh 
 +</​code>​
  
-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 / others) to do on an object (filesystem nodes).+To check if everything ​is OK, run the command ''​gdb''​ with no argumentsThe prompt should be similar to this:
  
-Standard UNIX actions are **Read**, **Write** and **Execute**,​ though their effects are different between files and directories:​ 
-  * **read**: allows opening for reading a file; for directories,​ allows listing their contents (e.g., ''​ls''​);​ 
-  * **write**: allows opening a file for writing; for directories,​ allows creating & deleting its children; 
-  * **execute**:​ allows executing a file; for directories,​ allows changing working directory inside (e.g., ''​cd''​). 
- 
-The [[https://​man7.org/​linux/​man-pages/​man5/​acl.5.html#​ACCESS_CHECK_ALGORITHM|verification algorithm]] is also simple: 
- 
-  * check if the user is the **owner** of the file; if true => apply the permissions in the owner slot; 
-  * check if the user is in the file's **group**; if true => apply the permissions in the group slot; 
-  * else: apply permissions in the **others** slot! 
- 
-<​note>​ 
-//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>​ 
- 
-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>​ <​code>​
-# Read The Friendly Manuals: +➜ gdb 
-man chmod +GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1 
-man chown+... 
 +pwndbg>
 </​code>​ </​code>​
  
-=== Special Permissions & Examples ===+Enter ''​q''​ to exit GDB. 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 ;)
  
-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: +===== Overview =====
-<​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 a directory, only that directory'​s owner or root can delete or rename the directory'​s files.+
  
-Example: //chmod 4762 myfile// translates ​to+A buffer overflow occurs when data written ​to a buffer overruns its boundary and overwrites adjacent memory locations, due to insufficient bounds checking. Thus, an 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 call) saved on stack and execute ​its own malicious ​code!
-<​code>​ +
-setuid = on +
-setgid = off +
-sticky bit = off +
-user = read + write + execute +
-group = read + write +
-other = write +
-</code>+
  
-In addition to setting permissions numerically,​ you can use addition and substraction operators: +{{:isc:​labs:​stack_layout.png?​700}}
-<​code>​ +
-chmod u+w = add write to *user* +
-chmod g-rw = remove read and write from *group* +
-chmod o-rwx = remove read, write and execute from *other*+
  
-chmod u+s = add setuid +Also check out one of the resources linked on top ^^ !
-chmod g-s = remove setgid +
-chmod o+t = add sticky bit+
  
-chmod a+w = add write to *all* +<note tip> 
-chmod a-wx = remove write and execute from *all* +This representation of the stack is valid for 32 bit programs. The calling convention is to save the parameters on the stack.
-</code>+
  
-More examples: +To find out what's different for a 64 bit program check this [[https://​www.systutorials.com/​x86-64-calling-convention-by-gcc/​|website]]. 
-<​code>​ +</note>
-chmod u=rwx,go=r = set read, write, execute on *user* and read, write on *group* and *other* +
-chmod go=  = remove all permissions on *group* and *other* +
-</code>+
  
-Another useful option is **-R**. It allows you to modify objects **recursively**,​ changing permissions on all objects in a directory and its subdirectories. 
-<​code>​ 
-chmod -R 755 myfolder 
-# same goes for chown: 
-chown -R student:​teachers myfolder 
-</​code>​ 
  
-==== Linux Access Control Lists ====+===== GDB primer =====
  
-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 permissionNow, we want to give to //mark// the following permissions:​ read and write (but not execute permission),​ but not to the others!+Please check out [[https://users.ece.utexas.edu/~adnan/gdb-refcard.pdf|a GDB cheatsheet]] for the most common operations.
  
-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 permissions. Therefore, 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.+You should see how to:
  
-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 a binary inside GDBpass arguments (and, for advanced cases: programmatic standard input -- which ''​pwntools''​ will later prove very useful for!); 
 +  ​add ''​break''​points & execution control (''​n''​ / ''​s''​ / ''​ni''​ / ''​si''​ / ''​c''​);​ 
 +  ​display variables and memory contents ​(''​p''​ / ''​x''​ + C expressions + various formats)
 +  ​backtrace / frame printing & navigation;​ 
 +  ​use ''​info''​ to see breakpoints / symbols;
  
-=== Displaying access permissions ===+Please read [[:​isc:​labs:​05:​extra:​gdb-tutorial]] if you're missing any of the above knowledge.
  
-The ''​getfacl''​ command ​displays ​the file name, owner, group and the existing ACL for a file. +[[https://​github.com/​pwndbg/​pwndbg|PwnDbg]] is a very nice GDB plugin (written in Python) which displays ​a 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:
  
 <​code>​ <​code>​
-student@isc-vm:~$ getfacl runme.sh ​ +22              if (argc == 1) { 
-file: my-script.sh +LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA 
-# ownermark +─────────────────────────[ REGISTERS / show-flags off / show-compact-regs off ]────────────────────────── 
-# groupsysop +*EAX  0xffffd880 ◂— 0x2 
-user::rw+*EBX  0x56558fcc (_GLOBAL_OFFSET_TABLE_) ◂— 0x3ed4 
-group::rw+*ECX  0xffffd880 ◂— 0x2 
-other::r--+*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>​
  
-=== Setting ACLs of files ===+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. 
 +With the original GDB you would have to manually print registers, disassemble code and inspect the stack. Thanks, God, for PwnDbg!
  
-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. +==== Exercises ====
  
-<​code>​ +=== 00Preparation ===
-setfacl -m ugo:<​user_or_group_name>:<​permissions>​ PATH... +
-</​code>​+
  
-Examples: +Download ​the {{ :isc:labs:lab05-code.zip | lab archive }} and unpack it somewhere in your home.
-<​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 modifies) a 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 ''​make''​.
  
-The ''​-x''​ option removes rules in a file or folder'​s ACL, e.g.: +=== [20p] 01Obfuscated Code ===
-<​code>​ +
-setfacl ​ -x  u:​mark ​ runme.sh  ​=> Removes mark's rule on runme.sh +
-</​code>​+
  
-===== Tasks =====+  * Run the ''​obfusflag''​ binary; you may study the code, but your task is clear: find out the obfuscated flag! 
 +    * Use ''​gdb'',​ ofc! 
 +    * Trouble navigating through the runtime code? see the tutorials / cheatsheets above!
  
-==== 00. Setup ==== +<note tip> 
- +To change ​variable without typing info built-in ​(not compiled using ''​-g''​), take the variable'​s address, cast to pointer of desired type then dereference:<​code>​ 
-All tasks will be solved inside ​Docker container ​(available on Docker Hub): +set variable *(int *)&​myvar = value
-<​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>​ </​code>​
 +</​note>​
  
-**Alternatively**,​ if you receive a "rate limit" error from Docker Hub**try out the GitHub-based repos**: <code bash+    ​Hint: you're on 64-bitcheck the links above for the calling convention... 
-docker pull ghcr.io/cs-pub-ro/​isc-acl-lab:latest +    ​Hint 2you also don't have debugging info compiled-in,​ so you must use disassembly to find the RBP offset of the ''​buf''​ variable; 
-docker run --rm --name acl-lab -it ghcr.io/​cs-pub-ro/​isc-acl-lab +<spoiler In case of emergency, expand
-</code+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>
  
-If you wish to open multiple terminals inside the same container, find the container'​s name and use ''​docker exec'':​ +<​solution -hidden> 
-<​code ​bash+<​code>​ 
-docker container ls +# gdb obfusflag 
-note the container'​s name or hash -copy it! +gdb> break check_fl0gz0rx 
-docker exec -it "<​CONTAINER_ID>" bash+gdb> run 12345678901234567890 
 +gdb> set var *(int*)&​deez = 1 
 +gdb> tbreak *check_fl0gz0rx + 159   before strcmp 
 +gdbcontinue 
 +gdbx/10s $rbp - 0x30  # find out buf's RBP offset from disass
 </​code>​ </​code>​
 +</​solution>​
  
-<note warning>​ +=== [50p] 02Stack overflow (EZ) ===
-Since you are running the containers locally, you may be temped to cheat by entering using the root user...+
  
-This defeats ​the purpose ​of the labso: **don't do that**!+  * Run & study the ''​buffovf''​ binary. There is a vulnerability in there, can you see it? 
 +  * Yep, you **must** use stack overflow to get this flag! 
 +  * First, try to crash the program. Use programmatically generated input (e.g., from Python3); 
 + 
 +<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>​ 
 +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 sequence. This 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''​
 </​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''​ 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 made of **numbers**). 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"\xb6\x91\x04\x08"​ + b"​\x12\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.1712049395.txt.gz · Last modified: 2024/04/02 12:16 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