Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 38 guests and 2 members online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Programmingarrow Problem with a shellcode...
EH-Net
May 22, 2013, 11:21:11 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1] 2 3   Go Down
  Print  
Author Topic: Problem with a shellcode...  (Read 17421 times)
0 Members and 1 Guest are viewing this topic.
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« on: May 13, 2010, 07:17:28 AM »

Hi,

I have an odd problem when trying to write my own exploit. I am doing the "extra mile" exercises for Win32 the Buffer-Overflow in the PWB course. So everything I am doing is legal here. Everything goes very well but one little thing.

I understand that injecting a null byte (\x00) will cause problems during the execution. But I have discovered that when I try to inject bytes ranging from \x0A to \x0F, I get a similar problem. Here is an example:

Let's say I want to inject the following code:
\x41\x42\x43\x44\x45\x0A\x46\x47\x48\x49

The debugger will show that the end result is something like:
\x41\x42\x43\x44\x45\x5A\x6B\x31\x5C\x61

But if I remove this \x0A character, I get the full message copied at the proper location: \x41\x42\x43\x44\x45\x46\x47\x48\x49

Basically, it seems I successfully copy my code, but starting at one of the mentioned characters, I only get garbage...

Any REAL experts?  Wink



Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
zeroflaw
Full Member
***
Offline Offline

Posts: 208



View Profile
« Reply #1 on: May 13, 2010, 07:47:48 AM »

Hmm 0x0A is the newline character, and the other chars are like tabs and a carriage return. Maybe it breaks the shellcode somehow. Though I've only read that shellcode can't contain null bytes Huh
« Last Edit: May 13, 2010, 07:52:20 AM by zeroflaw » Logged

ZF
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #2 on: May 13, 2010, 07:51:49 AM »

I forgot to say I am using a VPN. I first thought my firewall could be blocking these characters, but I soon woke up and realize the VPN encrypts everything. So it isn't my firewall.

Could it be an encoding problem of some sort?
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
mambru
Jr. Member
**
Offline Offline

Posts: 98


View Profile
« Reply #3 on: May 13, 2010, 11:19:36 AM »

The null byte (\x00) is not the only byte that may finish your string. Before crafting your payload you must detect which bytes will cause the application to finish your string, so you avoid them in the payload.

Check the next url for reference:

http://en.wikibooks.org/wiki/Metasploit/WritingWindowsExploit#Dealing_with_badchars
Logged
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #4 on: May 13, 2010, 12:33:48 PM »

Thanks mambru, I will read it tonight.

Also, I will post my solution.
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
sil
Hero Member
*****
Offline Offline

Posts: 549



View Profile WWW
« Reply #5 on: May 13, 2010, 03:53:55 PM »

Let's say I want to inject the following code:
\x41\x42\x43\x44\x45\x0A\x46\x47\x48\x49

The debugger will show that the end result is something like:
\x41\x42\x43\x44\x45\x5A\x6B\x31\x5C\x61

Any REAL experts?  Wink

NOP's are 90's... In that case, xor eax, eax is your friend... You can replace NOP's by zeroing them out, replacing them, etc.. e.g.:

Code:
\x31\xdb\x31\xc0\xb0\x01\xcd\x80

//xor eax,eax
//xor ebx,ebx
//mov al,1
//int 0x80

http://lordparody.wordpress.com/2010/03/09/just-slide/
http://www.vividmachines.com/shellcode/shellcode.html#as
http://mishou.org/2009/12/12/insecure-programming-by-example-shellcode-stack5-c/
http://webcache.googleusercontent.com/search?q=cache:ToYj-Yq3m-UJ:nostarch.com/extras/hacking/chap2/print2.asm+zero+out+nop+sled&cd=6&hl=en&ct=clnk&gl=us&client=firefox-a

Have you tried zeroing it out. How much space do you have to play with, etc.
Logged

H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #6 on: May 13, 2010, 05:08:13 PM »

I know now that I can encode my shellcode using the msfencode or something similar. So that is fine now.

BUT, my problem is the my ESP register needs to get the value \x0A\xAF\xD8\x77 but I have a problem with \x0A... Can I encode a value in EIP?

I will check right now!
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #7 on: May 13, 2010, 05:13:02 PM »

I just checked and like I thought, it becomes too big!

When I "msfencode" \x0A\xAF\xD8\x77, I get:

"\xda\xc9\xd9\x74\x24\xf4\xbb\x6d\x18\xd7\xa6\x2b\xc9\x5a" +
"\xb1\x05\x83\xc2\x04\x31\x5a\x14\x03\x5a\x79\xfa\x22\xfa" +
"\xf9\xca\x8d\x5f\x81\x6b\x48\x3c\x09\x28\x6c\xe0\x91\x87" +
"\xbb\x12"

This can't fit in EIP.

I am so humble now...  Undecided But I will mak it work!!!  Smiley
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
n1p
Jr. Member
**
Offline Offline

Posts: 89


View Profile WWW
« Reply #8 on: May 13, 2010, 05:20:49 PM »

It is not meant to fit in EIP... That is your encoded shellcode, if you are looking for a valid return address i.e. start of your shellcode, it should not contain what can be considered bad characters - \x0d\x00\x0a.

Ensure EIP points to a NOP sled to your shellcode or directly into your shellcode. If you have correctly aligned your offsets, attempt to fill EIP with \xCC\xCC\xCC\xCC to get your debugger to break and show you whats going on.

Happy to take a look for you, but if it is course material, I doubt is allowed.
Logged
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #9 on: May 13, 2010, 05:50:44 PM »

Thanks guys, you are really helping me here!!

First, I could easily get the exploit on the internet, but I want to learn, so here I am!

Also, here is what I was successful doing:
1) I can set, let say, \x41\x41\x41\x41 in EIP (basicaly, I control EIP)
2) I successfully encoded my shellcode.
3) I have added a 16 bit long NOP sled at the beginning of ESP and my shellcode is right after.
4) I have verified that my shellcode in the memory of the program is identical to the one I have in my code. It is indeed identical.

I keep trying...
« Last Edit: May 13, 2010, 05:53:27 PM by H1t M0nk3y » Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #10 on: May 13, 2010, 06:04:16 PM »

I think I just solved my problem.

I found another JMP ESP instruction in users32.dll which doesn't contain any infamous characters. I am now able to reach the beginning of my shell code...

I can feel it, i is so close!!!
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #11 on: May 13, 2010, 06:16:41 PM »

I have got a bind shell from my FIRST exploit!!!!

Thanks n1p, sil, mambru and zeroflaw. I appreciate it!

As a note, I feel like, when I started going on racetrack with my racebike, the first time I touch my knee on the pavement in a curve. Brilliant!

I am so happy, and I am all alone tonight at home!  Grin

Ouff, I need a beer now!  Tongue
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
mambru
Jr. Member
**
Offline Offline

Posts: 98


View Profile
« Reply #12 on: May 13, 2010, 10:23:40 PM »


No problem M0nk3y, I'm glad I was helpful in some way and you did it, I was on the same road a while ago (PWB course) Wink
Logged
zeroflaw
Full Member
***
Offline Offline

Posts: 208



View Profile
« Reply #13 on: May 14, 2010, 01:51:56 AM »

You're welcome H1t M0nk3y! Glad to see you got it working. Good job Cool
Logged

ZF
sil
Hero Member
*****
Offline Offline

Posts: 549



View Profile WWW
« Reply #14 on: May 14, 2010, 09:44:55 AM »

I have got a bind shell from my FIRST exploit!!!!

NP and congrats. I'm going over a lot of advanced shellcoding tutorials and videos right now as well. My goal is repeatability across the board. Dino Zovi and Alex Sotirov have a class I'm waiting to attend called Assured Exploits. (http://trailofbits.com/2010/02/25/assured-exploitation-training/)

For example... Right now I have quite a few POC's and exploits for a variety of applications (I focus on the big boys, Oracle, IBM, etc. for obvious reasons Wink) Sometimes I submit work to CERT (they take forever even to get me my VRU's), sometimes I go to ZDI, sometimes IDefense, etc... Anyhow, I hate having something proven exploitable on say Windows 2003 Advanced Server, but not on say Win2008, Win7, etc.

I've been banging my head in reading especially for Win7 right now. E.g., I have one application, completely 'ownable' on everything EXCEPT Win7. I almost always get Access Violations on HuhHuh? no matter what I do. A huge majority of things I find on say XP, I can replicate after a while on Vista, but on Win7 the same exploit almost always goes to kernelbase.dll so I've been trying to figure out why. It's a fun and sometimes frustrating experience.

n1p's document is definitely worth reading and again n1p if you read this, WinDBG rocks! So if you get one of those going let me know maybe I can learn more or even assist. H1t M0nk3y, I almost never suggest that anyone stray from what works for them however... I do have to state that WinDBG for debugging to me is more powerful. Not to mention the byakugan module would have found the right addresses for you:

Quote
What can you do with byakugan.dll ?

jutsu : set of tools to track buffers in memory, determining what is controlled at crash time, and discover valid return addresses
pattern_offset
mushishi : framework for anti-debugging detection and defeating anti-debugging techniques
tenketsu : vista heap emulator/visualizer.

identBuf / listBuf / rmBuf : find buffers (plain ascii, metasploit patterns, or data from file) in memory…

memDiff : compare data in memory with a pattern and mark the changes. This will help you determining whether e.g. shellcode has been changed/corrupted in memory, whether certain ‘bad characters’ need to be excluded from shellcode, etc
hunt

findReturn : search for the addresses that point to a usable function to return to.

searchOpcode : converts assembler instruction to opcode, AND it lists all executable opcode sequence addresses at the same time.

http://www.corelan.be:8800/index.php/2009/09/05/exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-basic-exploit-development/?nomobile

WinDBG rocks... Immunity's Debugger (as does Canvas) for those who use then has some cool stuff in it as well. I need to update Canvas :| The only time I fire up olly nowadays is for mapping :|
Logged

Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.08 seconds with 22 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Free Business and Tech Magazines and eBooks

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.