Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 06-19-2013, 11:04 PM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › Assembly v
« Previous 1 2 3 Next »

Assembly AT&T on BSD + Making shellc0de for FreeBSD System

Home General Computer Multimedia Business Lounge

Post Reply 
Tweet
Threaded Mode | Linear Mode
Assembly AT&T on BSD + Making shellc0de for FreeBSD System
04-24-2011, 10:23 AM (This post was last modified: 04-24-2011 10:23 AM by mywisdom.)
Post: #1
mywisdom Offline
Administrator
*******
Administrators
Posts: 923
Joined: Dec 2009
Reputation: 51
Assembly AT&T on BSD + Making shellc0de for FreeBSD System
Assembly AT&T on BSD + Making shellc0de for FreeBSD System

this article was written by : myw1sd0m a.k.a wisdomc0de a.k.a m0nk3y

greets: peneter,gunslinger, flyf666, superman,ketek,chaer,we nkhairu,wahyu,n0te,blackn0te,kumbang and all devilzc0de crew and members

I'm getting dizzy while modifying worm into botnet, so let's play before we start develop again.

Today We're gonna play on a toy : Assembly Toys on BSD + Making shellc0de on FreeBSD i386 Machine


------------------------------
* uname -a

we'll be using freebsd 6.3 here:
%uname -a
FreeBSD whereisthehostnameazzh0le 6.3-PRERELEASE FreeBSD 6.3-PRERELEASE #1 whereisthedateazzh0le

we're goin to use gnu asm as our compiler today


* Syscalls

syscall lists at freebsd located at :/usr/src/sys/sys/syscall.h

at first we're goin to write a little program that display this string: devilzc0de

as always it will invoke these syscalls:
1. sys_write

the c declaration is : ssize_t write(int fd, const void *buf, size_t count);

%cat /usr/src/sys/sys/syscall.h | grep write
#define SYS_write 4
/* 68 is obsolete vwrite */
#define SYS_writev 121
#define SYS_pwrite 174
#define SYS_pwritev 290
#define SYS_aio_write 319
--------------

yeah we're goin to use this: #define SYS_write 4

%eax will be $4 (sys_write)
%ebx goes our fd number , 0=stdin 1=stdout and 2=stderr (http://en.wikipedia.org/wiki/File_descriptor)
%ebx goes for buffer
%edx goest for string length


%ebx (fd) ---------- %ecx (buf)---------------%edx (size, i meant length of devilzc0de string)----------------------%esi-------------------%edi

where %eax will be our retval.

this scheme always happen on every syscall below 6 arg(s), so if it's 4 args the next arg will be on %esi and if it's 5 args the next will be at %edi


------------------
%pico devilzc0de.s
UW PICO™ 4.10 File: devilzc0de.s


so to make these sys_write with string devilzc0de, here is our code sys_write and it ends with a sys_exit:


-------------------------
.section .rodata
evilbuf:
.ascii "devilzc0de"
len = . - evilbuf


.globl _start
_start:


pushl $len
pushl $evilbuf
pushl $1
movl $4,%eax
pushl %eax
int $0x80

_out:
movl $1, %eax
pushl $0
pushl %eax
int $0x80

--------------------

to assemble just type these:

%as -o devilzc0de.o devilzc0de.s

then we can linker:

%ld -o devilzc0de devilzc0de.o

%./devilzc0de
devilzc0de%


we may see the arguments from each syscalls that we've executed above using strace:
-----------------------
%strace ./devilzc0de
execve(0xbfbfe760, [0xbfbfec48], [/* 0 vars */]) = 0
write(1, "devilzc0de", 10devilzc0de) = 10
exit(0) = ?
%
-------------------------

write(1, "devilzc0de", 10devilzc0de) = 10

fs=1 -> stdout
next is content of buffer: devilzc0de
string length=10

exit(0) -> we exit with 0 as our return value as we may see here:

---------------
%echo $?
0
%
---------------

we may exit with other retval:

%cat keluar.s

.globl _start
_start:
movl $1, %eax
pushl $1
pushl %eax
int $0x80



%as -o keluar.o keluar.s
%ld -o keluar keluar.o
%./keluar
%echo $?
1
%


* Making exit shellcode

ok let's try to make an exit shellcode


example from this asm code:

%cat keluar.s

.globl _start
_start:
movl $1, %eax
pushl $1
pushl %eax
int $0x80



%objdump -d keluar

keluar: file format elf32-i386-freebsd

Disassembly of section .text:

08048074 <_start>:
8048074: b8 01 00 00 00 mov $0x1,%eax
8048079: 6a 01 push $0x1
804807b: 50 push %eax
804807c: cd 80 int $0x80



here's the freebsd shellc0de: \xb8\x01\x00\x00\x00\x6a\x01\x50\xcd\x80

then we must avoid null byte

by changing $eax to %al (we must switch movl to mov because movl means mov long), we've made our new shellcode:

%objdump -d keluar

keluar: file format elf32-i386-freebsd

Disassembly of section .text:

08048074 <_start>:
8048074: b0 01 mov $0x1,%al
8048076: 6a 01 push $0x1
8048078: 50 push %eax
8048079: cd 80 int $0x80
%

so our final shellcode is:

\xb0\x01\x6a\x01\x50\xcd\x80

let's using in our c:

/**freebsd exit shellcode with return value : 1
made by: mywisdom**/
#include <stdio.h>
char shellcode[] = "\xb0\x01\x6a\x01\x50\xcd\x80";
int main()
{
fprintf(stdout,"Length: %d\n",strlen(shellcode));
(*(void(*)()) shellcode)();
}


%gcc -o x x.c
%./x
Length: 7
%


length=7 ??? have a look below:


\xb0 \ x01 \ x6a \ x01 \ x50 \ xcd \ x80

1 2 3 4 5 6 7

each hex split represent 1 decimal Length: %d\n",strlen(shellcode)


* the inline asm

for inline asm we may use:
__asm__(" asm code here")

or we may use:

asm(" asm code here ")


how to insert aboce freebsd asm code inlinely?? here they come:

#include <stdio.h>
int main()
{
__asm__("mov $0x1,%al\t\n"
"push $0x1\t\n"
"push %eax\t\n"
"int $0x80");


}



* asm volatile technic

this asm volatile tehcnic will force gcc not to optimize our asm code until this asm finish

here if we're gonna use asm volatile:

----------------
#include <stdio.h>
int main()
{
asm volatile("mov $0x1,%al\t\n"
"push $0x1\t\n"
"push %eax\t\n"
"int $0x80");

}
-------------------
Find all posts by this user
Quote this message in a reply
04-24-2011, 10:54 AM
Post: #2
putri sitasari Offline
cewek cantik calon presiden
Posts: 100
Joined: Jan 2011
Reputation: 6
RE: Assembly AT&T on BSD + Making shellc0de for FreeBSD System
fufufufufu pu3 mawu pertamax duyu di thread keyenzz ^^v
mbil belajar tyuz QuWh b4c4 eEa k4g cihuy
unyu-unyu
Find all posts by this user
Quote this message in a reply
04-24-2011, 11:11 AM
Post: #3
selfdefense Offline
./Devilz Commodore
Posts: 1,294
Joined: Aug 2010
Reputation: 58
RE: Assembly AT&T on BSD + Making shellc0de for FreeBSD System
wahhhh... ane baru aja belajar freebsd nih om... asik
makasih om tutornya... mantap
Find all posts by this user
Quote this message in a reply
04-24-2011, 07:30 PM
Post: #4
wahyu_devilzc0de™ Offline
Rest In Peace
***
Posts: 1,573
Joined: Dec 2009
Reputation: 191
RE: Assembly AT&T on BSD + Making shellc0de for FreeBSD System
mantep tenan mantap joss .
Visit this user's website Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Rainbow [Tutor] Basic Assembly 8 Bit mr_nothing 9 156 06-11-2013 08:24 PM
Last Post: mr_nothing
Rainbow [Tutor] Pemrograman Bahasa Assembly Untuk Trafic Light mr_nothing 6 155 06-09-2013 07:17 PM
Last Post: hakimoxz
Rainbow [Tutor] Pengalamatan memory pada assembly 8 bit mr_nothing 9 147 06-09-2013 04:14 PM
Last Post: ditatompel
  Pemrograman Assembly di Windows dengan masm32+ debugging dg ollydbg mywisdom 7 1,478 06-05-2013 02:55 PM
Last Post: rifqirachel
  Assembly 32 bit and shellc0d3 mywisdom 2 1,977 02-11-2013 08:56 PM
Last Post: ghosthands
  The Art Of Assembly ian182 8 1,605 02-08-2013 10:49 PM
Last Post: ghosthands
  Just another guy asking how to learn assembly ? mandi 3 270 02-08-2013 10:47 PM
Last Post: ghosthands
  method/fungsi pada assembly syn_attack 4 511 05-19-2012 12:35 AM
Last Post: zard22
  pemrograman di ms dos dengan assembly 16 bit+ analisa beberapa virus asm mywisdom 8 1,797 01-21-2012 04:04 AM
Last Post: oootrxooo
Tongue [Tutor] Iseng with Assembly nyiurmelambai 12 1,176 01-17-2012 05:30 PM
Last Post: darkdante

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 06-19-2013, 11:04 PM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE