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 35 guests online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Malwarearrow Encoding parts of a payload
EH-Net
May 21, 2013, 10:34:19 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   Go Down
  Print  
Author Topic: Encoding parts of a payload  (Read 3355 times)
0 Members and 1 Guest are viewing this topic.
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« on: February 11, 2013, 10:28:37 AM »

Hi everyone,

When I use msfpayload to generate my payload (let's say, a Windows tcp bind shell), I always encode it with msfencode to remove null bytes (\x00) or any other characters (usually \x0a and \xff, sometimes more). I do this because these bytes would otherwise prevent the insertion of my payload in memory.

But what if my payload needs to be cut in two because I cannot put it all at the same memory location? For example, if my payload is 300 bytes long and I only have two spots of 200 bytes in memory? Should I carefully cut the payload (between two instructions) then encode each part separately, if they contain any invalid bytes? I would finally jump from the first part to the second one.

I haven't hit this problem yet, I was just "meditating" on the issue and couldn't get a good answer from Google.

Thanks
Logged

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

Posts: 1235


View Profile
« Reply #1 on: February 11, 2013, 10:36:54 AM »

Breaking the shellcode into several parts should work, but you have to verify where you separate it. If your first staged buffer is very limited in space you could also utilize an egg hunter to get eventually your shellcode executed.
Logged
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #2 on: February 11, 2013, 12:00:54 PM »

Yes, I guess it's better to search harder to find a bigger place in memory where you wouldn't have to break the payload.

But just for the sake of it, have you ever encode parts of your payload?
Logged

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

Posts: 561


View Profile WWW
« Reply #3 on: February 11, 2013, 04:49:14 PM »

I literally just had this last problem on the latest bug I posted. Just slapped together a blog post last night: http://www.pwnag3.com/2013/02/actfax-raw-server-exploit.html

Bottom line, you can cut up the payload easily. However, if you mess with the payload being sent sometimes the memory layout/registers will be completely different and show you something better or worse. In my case, 4 bytes literally changed the entire structure...
Logged

ajohnson
Recruiters
Hero Member
*
Offline Offline

Posts: 1057


aka dynamik


View Profile WWW
« Reply #4 on: February 11, 2013, 07:43:18 PM »

I literally just had this last problem on the latest bug I posted. Just slapped together a blog post last night: http://www.pwnag3.com/2013/02/actfax-raw-server-exploit.html

Bottom line, you can cut up the payload easily. However, if you mess with the payload being sent sometimes the memory layout/registers will be completely different and show you something better or worse. In my case, 4 bytes literally changed the entire structure...

How in the world do you have time for bug hunting? Shocked

Also, is that a standard fuzzing template? My coworker is currently playing around with Ability in the OSCP labs. He sent me his fuzzer for review, and it looked almost identical to yours, but with FTP commands.

Hi everyone,

When I use msfpayload to generate my payload (let's say, a Windows tcp bind shell), I always encode it with msfencode to remove null bytes (\x00) or any other characters (usually \x0a and \xff, sometimes more). I do this because these bytes would otherwise prevent the insertion of my payload in memory.

But what if my payload needs to be cut in two because I cannot put it all at the same memory location? For example, if my payload is 300 bytes long and I only have two spots of 200 bytes in memory? Should I carefully cut the payload (between two instructions) then encode each part separately, if they contain any invalid bytes? I would finally jump from the first part to the second one.

I haven't hit this problem yet, I was just "meditating" on the issue and couldn't get a good answer from Google.

Thanks

Yea, that's going to be a pain because you're going to have to do a lot of that manually. As you noted, you can't just cut it in half and add a jump to the next portion. Not only will you need to encode each portion separately, you'd also need to correct any jumps and other offsets in the original shellcode. I'd try to get the exploit working without encoding first by binary pasting the shellcode into the appropriate places in a debugger, and then go back and dealing with encoding once the shellcode was functional. Just break it out into as many baby steps as you can.

It also depends on how big the gap is. There was a cool example in the Corelan course where the shellcode was broken by a double word, so a few instructions were added to the beginning of the shellcode to correct those four bytes. Something like that would certainly be a less involved solution, if possible.
Logged

WIP: GCFA | www.infosiege.net | @infosiege

The day you stop learning is the day you start becoming obsolete.
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #5 on: February 11, 2013, 07:45:03 PM »

Quote
However, if you mess with the payload being sent sometimes the memory layout/registers will be completely different and show you something better or worse.
That's a very good point. I just read your blog and I found it very well explained and easy to follow. Good job cd1zz!!

Quote
How in the world do you have time for bug hunting?
Did you guys know that cd1zz (Craig Freyman) has 19 exploits to his name in exploit-db?  That's insane!!! Shocked
http://www.exploit-db.com/search/?action=search&filter_page=1&filter_description=&filter_exploit_text=&filter_author=Craig+Freyman&filter_platform=0&filter_type=0&filter_lang_id=0&filter_port=&filter_osvdb=&filter_cve=
« Last Edit: February 11, 2013, 07:51:23 PM by H1t M0nk3y » Logged

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

Posts: 561


View Profile WWW
« Reply #6 on: February 11, 2013, 08:43:16 PM »

@ajohnson I've had it for so long, I completely forgot where it came from. This is it: http://www.redteamsecure.com/labs/post/18/build-your-own-ftp-fuzzer

Editing the post now to reflect that!

Logged

UNIX
Hero Member
*****
Offline Offline

Posts: 1235


View Profile
« Reply #7 on: February 12, 2013, 01:25:55 AM »

Nice write-up on the ActFax exploitation, cd1zz. Wink
Logged
ajohnson
Recruiters
Hero Member
*
Offline Offline

Posts: 1057


aka dynamik


View Profile WWW
« Reply #8 on: February 12, 2013, 03:51:47 AM »


Oh, I'm well aware of his... *wait for it* ...many exploits.

Sorry, I couldn't resist an awful pun Grin

Seriously though, he was one of the few that was consistently finishing ahead of me in the Corelan course. He's a frustratingly sharp guy Cool
Logged

WIP: GCFA | www.infosiege.net | @infosiege

The day you stop learning is the day you start becoming obsolete.
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #9 on: February 12, 2013, 07:01:48 AM »

cd1zz and ajohnson: Have you taken the Corelan course before or after OSCE?

It looks good, but 80% of the class seemed to be covered by the Cracking the Perimeter course...

Am I right?
Logged

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

Posts: 561


View Profile WWW
« Reply #10 on: February 12, 2013, 08:07:17 AM »

There is a lot of overlap and in many cases they compliment each other. We had a thread on here somewhere where we got into the nitty gritty. For example, OSCE covers no ROP exploitation but Corelan does. Corelan is 110% exploit dev. OSCE is 90%. If possible, do them both!!

ajohnson just knocked out OSCE and recently did Corelan, he might have a fresher perspective...
Logged

H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #11 on: February 12, 2013, 08:55:30 AM »

OSCE is my goal right now, but I will keep a good eye on Corelan's tutorials at https://www.corelan.be/index.php/category/security/exploit-writing-tutorials/

Thanks to your blog cd1zz, I now know about these things.
« Last Edit: February 12, 2013, 09:04:13 AM by H1t M0nk3y » Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
ajohnson
Recruiters
Hero Member
*
Offline Offline

Posts: 1057


aka dynamik


View Profile WWW
« Reply #12 on: February 12, 2013, 12:14:19 PM »

I intend to do full write-ups on both, but my schedule's not going to clear up for the next few weeks.

In the interim, I think it's apples and oranges. Sure, they both cover exploit development, but there are huge differences in the tools, techniques, and approaches. As usual, OffSec focuses on doing everything manually and uses OllyDbg. The Corelan boot camp might as well be called "Exploit Development using Mona.py." You spend nearly the entire course in Immunity and working with Mona, from basic stack-based buffer overflows to egg hunters to ROP exploitation. The amount of annoying, tedious tasks that can be performed effortlessly with Mona is nothing short of amazing.

I think the Corelan course more accurately depicts how people who perform exploit development day-to-day go about their work. However, it's still important to understand what's going on behind-the-scenes and not rely on Mona as this magical tool that just works. Both courses compliment each other well, and I recommend doing both. Also, Peter is great to interact with, and being able to ask questions and bounce ideas around with him is a fantastic experience. He's going to work with you and not just tell you to try harder.

I actually took the Corelan course a couple of weeks before my OSCE exam, and one thing that did surprise me is that it really didn't help much, if at all, with the exam. I thought I would crush it for sure, but it ended up being the usual miserable experience with a miraculous pass in the last few hours. In fact, I actually ended up using a technique that wasn't covered in either course. I can't say more without spoiling it, but I posted my solution in the OffSec OSCE-only forums Wink

Also be sure to check out the SecurityTube assembly and exploit development videos, as well as the tutorials over at The Grey Corner (thanks to UNIX for showing me those).
Logged

WIP: GCFA | www.infosiege.net | @infosiege

The day you stop learning is the day you start becoming obsolete.
H1t M0nk3y
Hero Member
*****
Offline Offline

Posts: 864



View Profile
« Reply #13 on: February 12, 2013, 02:24:43 PM »

My list of things to read/review/do is getting longer and longer every day!!
Will I ever be able to challenge this exam?  Tongue

Thanks ajohnson, very useful, as usual!
Logged

OSCP, GPEN, GWAPT, GSEC, CEH, CISSP
Dark_Knight
Sr. Member
****
Offline Offline

Posts: 292


View Profile WWW
« Reply #14 on: February 24, 2013, 10:15:41 PM »

I literally just had this last problem on the latest bug I posted. Just slapped together a blog post last night: http://www.pwnag3.com/2013/02/actfax-raw-server-exploit.html

Bottom line, you can cut up the payload easily. However, if you mess with the payload being sent sometimes the memory layout/registers will be completely different and show you something better or worse. In my case, 4 bytes literally changed the entire structure...

I decided to throw my hat in the ring as well. Of course cd1zz has already done the heavy lifting and its not as sexy Smiley

http://sector876.blogspot.com/2013/02/hacking-actfax-raw-server.html
« Last Edit: February 24, 2013, 10:26:14 PM by Dark_Knight » Logged

CEH, OSCP, GPEN, GWAPT, GCIA
http://sector876.blogspot.com
Pages: [1] 2   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.07 seconds with 23 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
 
         
Advertisement

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