Theme Layout

Boxed or Wide or Framed

Wide

Theme Translation

Display Featured Slider

Featured Slider Styles

Display Grid Slider

yes

Grid Slider Styles

Display Trending Posts

Display Author Bio

Display Instagram Footer

off

Dark or Light Style

Light
Powered by Blogger.

Saturday, December 10, 2016

Shell Code

Shell Code




This Document is intended for research & study purposes. We warn you that any legal liability that arises when using this document for commercial or malicious purposes is at your own risk.

#Shell Code.

:In hacking, a shellcode is a small piece of code used as the payload in the exploitaion of a S/W vulnerability. It is called "shellcode" because it typically starts a command shell from which the attacker can control the compromised machine, but any piece of code that performs a similar task can be called shellcode. Because the function of a payload is not limited to merely spawning a shell, some have suggested that the name shellcode is insufficient. However, attempts at replacing the term have not gained wide acceptance. Shellcode is commonly written in machine code.   --from Wikipedia


#How to make Shell Code.

 The procedure for creating shell code is as follows.

  1.  Implement code that you want to run in C or another high-level language.
  2.  Disassembling using GDB and finding the required part.
  3.  Implement with only the essential parts required for system calls.
  4.  Compile and Output the machine language using Objdump.
  5.  If there is a null, Return a null value, Remove it by processing.
  6.  Complete machine code with one sentence.

 # Make the local shell code.

 :Local Shell Code refers to the shell code that operates in the local environment.
 The Shell Code to create is the code that executes the Root Shell using the execve  function in Red Hat Linux 9. The code contents are as follows.




The execve function is itself a System call function. If we look at the prototype of the execve function, the arguments of the execve functions are the execution path, the start address of the argument array, and the address of the enviroment variable array, respectively.
 Now, compile this code with the static option, and run it. we can see shell running as follows:



The static option is used to compile, not to use the shared lib, and to contain all the content used in the program.
 To create a shell code, we first need to implement it in assembly language. Therefore, we use GDB to get the information we need when coding with ASM.



If we disassembly the execve using GDB, you can see the ASM commands above. Put a bp on execve +36 where int0x80 ix located. and look at the values of registers as shown below.



When expressing execve (str[1], str, &str[1]), use eax, ebx, ecx and edx.  the system call number of execve is 11. the values of the execve receive as arguments are 0 address, the address of "/bin/sh", and "/bin/sh" and write as asm code, we can write as follows.



Use this code to check the machine code using objdump.



In order to function properly with the Shell Code, there must be no null characters. Examples of ways to remove null values include short jump, modify register width, and xor operation.
 These methods use only enough space for their own use, they can not enter Null. because they do not have space left.

The modified code that removed the null value is as follows.


Check again with objdump to see if there is a null value that could not be removed.


The shell code is extracted using this file because the null value no longer exists.


If we run this shell code, the shell will run fine, but we will not be able to run the shell with root permission. because there is no code to get root's privileges. Therefore, We need to add the code about getting root previlege. ex. setuid(0)


we check the system call number of Setuid() in /usr/included/unistd.h. we can see that it is 23 as shown above.

If we implement setuid(0) with asm, as follows.
  • mov eax,0x17
  • mov ebx,0
  • int 0x80
and we must remove the null values, the result is as follows.
  • xor eax,eax
  • mov ebx,eax
  • mov al,0x17
  • int 0x80
Then add the following to your existing file:


Now, we extract the completed asm file as shell code. then, Local shell code is completed.


Using the extracted shell code, make the following file.



If we compile this file and run it, we can see that Shell is run with root permission as follows.




Read more »
Unknown
0 Comments

You Might Also Like

[Pwnable.kr] Write up List.

[Pwnable.kr] Write up List.


# Write up List.



This page is the problem solving list document of pwnable.kr. The order of the list is by order of difficulty, the order in which I solved the problem. and may be different from order of the problems on the pwnable.kr. I created this page because it is not easy to find the problem I want in the category on this blog.



> Toddler's Bottle.

Read more »
Unknown
0 Comments

You Might Also Like

Friday, December 9, 2016

[Pwnable.kr/Toddler's Bottle] random ( Solved. 16.12.09 )

[Pwnable.kr/Toddler's Bottle] random ( Solved. 16.12.09 )


# Problem.

 This problem is about the random value. 


# How To Solve.

 First, Connect the server ssh random@pwnable.kr -p2222
 and I check the source code about the random.


According to the code, The core of the program is the XOR operation of key & random value. If the computed value is equal to 0xdeadbeef, we can see the flag.
Because of the large number of cases, I analyzed the random program using the GDB.
The results of the analysis are as follows.


I used the following method to find the key value by inverse operation of 0xdeadbeef and random value. 


Since the random value is in [rbp-0x4], So I put the breakpoint in the next line <+21> and run the program. And I checked the value in [rbp-0x4].
Finally, The key value could be obtained by XOR operation with 0xdeadbeef & 0x6b8b4567.




Read more »
Unknown
0 Comments

You Might Also Like

Thursday, December 8, 2016

[Pwnable.kr/Toddler's Bottle] Bof ( Solved 16.12.08 )

[Pwnable.kr/Toddler's Bottle] Bof ( Solved 16.12.08 )


# Problem.

  This problem is about the buffer overflow vulnerability.


# How To Solve.

  First of all, 
  Download bof ( http://pwnable.kr/bin/bof ) & bof.c ( http://pwnable.kr/bin/bof.c)  
  and i look the bof.c, it looks as follows.
  
  

first, look at the main function, I notice that the 0xdeadbeef is calling the func() as a transfer factor. and then, look the func() function, I notice that if key == 0xcafebabe, system("/bin/sh") is excuted. 
 To change the key value 0xcafebabe, I analyzed the bof using the gdb. 


and I disassemble <func>. It looks as follows.


From <+29> to <+40>, It can be seen that the distance from buffer to ret is 52bytes. So, I can change the key value by filling the dummy value by 52 bytes and filling with 0xcafebabe. 

Here is the payload and flag.



Read more »
Unknown
0 Comments

You Might Also Like

[Pwnable.kr/Toddler's Bottle] collision ( Solved 16.12.08 )

[Pwnable.kr/Toddler's Bottle] collision ( Solved 16.12.08 )


# Problem.


  This problem is about the MD5 hash Collision.


# How To Solve.

  first. connect the server ssh col@pwnable.kr -p2222
  and open the col.c using vi.


  look the check_password code. we notice that this code returns a res by adding the input value five times. 
  now at the main part, hashcode == check_password(argv[1]) 
Because the hashcode is 0x21DD09EC, the value of the finished check_password must also be 0x21dd093c.
therefore, we divide 0x21DD09EC by 0x05, the following formula is calculated.

0x21DD093C = 0x6C5CEC8 *5 + 4

Therefore, the value that we need to input to find the flag is as follows.

then, we can find the flag.


Read more »
Unknown
0 Comments

You Might Also Like

[Pwnable.kr/Toddler's Bottle]cmd1 ( Solved 16.12.08 )

[Pwnable.kr/Toddler's Bottle]cmd1 ( Solved 16.12.08 )


# Problem.

  Mommy! what is PATH environment in Linux?? 

# How to solve.

This problem is about the PATH in Linux. 
First, connect to the ssh cmd1@pwnable.kr -p2222 
After accessing the server and using the vim, we can see the source code about cmd1.




we can't use some keywords like flag, sh and tmp.
so, I used environment PATH. 

then, we can find the flag.


Read more »
Unknown
0 Comments

You Might Also Like

Wednesday, December 7, 2016

[Pwnable.kr/Toddler's Bottle] fd ( Solved 16.12.07 )

[Pwnable.kr/Toddler's Bottle] fd ( Solved 16.12.07 )



Mommy! What is a file descriptor in Linux?


This problem is about the file descriptor in Linux.  
As given, connect the ssh fd@pwnable.kr -p2222
when using the vim, we can see the source about fd.  
0x1234 is equal to 4660. So, we need to give 0x1234 ( 4660 in demical ) as argv[1]
then, Let see if(!strcmp("LETMEWIN\n", buf). 
at that point, the return value must be 1. 
so, we also input the "LETMEWIN\n" 



as a result, we can find the flag. 
"mommy! I think I know what a file descriptor is!!"












Read more »
Unknown
0 Comments

You Might Also Like

Follow @SunriseSunsetBlog