Hello everyone! In this write-up, we are going to solve a Reflected XSS vulnerability lab on Hackviser. The goal of this lab is to find a way to escape an HTML attribute and trigger an XSS payload without breaking the website's functionality.
Initial Exploration
When we first access the lab environment, we are greeted with an "Art Gallery" page containing several buttons representing different paintings.

Clicking on the artworks changes the image displayed on the screen and updates the URL. We notice the art parameter in the URL (e.g, ?art=the-starry-night).
Testing the Parameter
To understand how the backend processes our input, we need to send a simple test string. I changed the value of the art parameter in the URL to test (?art=test).

As a result, the image on the page broke, indicating that our input directly affects the image path.
Inspecting the Page Source
To see exactly where and how our input is reflected in the DOM, we need to inspect the page source. By viewing the source code, we can locate our test string.

As seen in the source code, our input is reflected directly inside the src attribute of an <img> tag: <img ... src="assets/images/test.jpg"/>
Crafting the Payload
Since our input is trapped inside the src attribute, traditional payloads like <script>alert(1)</script> or the javascript: pseudo-protocol won't work directly. We need to escape the attribute and introduce a JavaScript event handler.
We can achieve this by:
- Closing the double quote of the
srcattribute:" - Adding the
onerrorevent handler, which executes JavaScript if the image fails to load:onerror="alert(1)
Our Payload: " onerror="alert(1)
Execution and Triggering XSS
We inject our crafted payload into the URL parameter. The URL becomes: ?art=" onerror="alert(1)
When the browser parses this, the HTML turns into: <img ... src="assets/images/" onerror="alert(1).jpg"/>
(Note: The trailing
.jpgdoesn't break the payload because the JavaScript engine executes the validalert(1)function first, right before it encounters the syntax error caused by the.jpgstring.)
Since assets/images/ is an invalid image path, the browser fails to load the image. This failure immediately triggers our onerror event handler, executing the alert(1) function.

And there we have it! We successfully triggered the XSS vulnerability by manipulating the HTML attribute.
Herkese merhabalar. Bu yazıda, Hackviser üzerindeki bir Reflected XSS zafiyeti laboratuvarını çözeceğiz. Bu laboratuvarın amacı, web sitesinin işleyişini bozmadan bir HTML özniteliğinden (attribute) kaçmanın ve bir XSS zararlı payloadını tetiklemenin bir yolunu bulmaktır.
İlk İnceleme
Laboratuvar ortamına ilk eriştiğimizde, farklı tabloları temsil eden birkaç butonun bulunduğu bir "Art Gallery" sayfasıyla karşılaşıyoruz.

Sanat eserlerine tıkladığımızda ekranda görüntülenen resim değişiyor ve URL güncelleniyor. URL'de art parametresinin kullanıldığını fark ediyoruz (örneğin, ?art=the-starry-night).
Parametreyi Test Etme
Arka planın (backend) girdimizi nasıl işlediğini anlamak için basit bir test metni göndermemiz gerekiyor. URL'deki art parametresinin değerini test olarak değiştirdim (?art=test).

Bunun sonucunda sayfadaki resim kırıldı, bu da girdimizin doğrudan resim yolunu (image path) etkilediğini gösteriyor.
Sayfa Kaynağını İnceleme
Girdimizin DOM'da (Belge Nesne Modeli) tam olarak nereye ve nasıl yansıdığını görmek için sayfa kaynağını incelememiz gerekiyor. Kaynak koduna bakarak test metnimizi bulabiliriz.

Kaynak kodunda görüldüğü gibi, girdimiz doğrudan bir <img> etiketinin src özniteliği (attribute) içine yansıtılıyor: <img ... src="assets/images/test.jpg"/>
Payload Oluşturma
Girdimiz src özniteliğinin içine hapsolduğu için, <script>alert(1)</script> veya javascript: sözde protokolü (pseudo-protocol) gibi geleneksel payload'lar doğrudan çalışmayacaktır. Öznitelikten kaçmamız ve bir JavaScript olay yakalayıcısı (event handler) eklememiz gerekiyor.
Bunu şu şekilde başarabiliriz:
srcözniteliğinin çift tırnağını kapatarak:"- Resim yüklenemediğinde JavaScript çalıştıran
onerrorolay yakalayıcısını ekleyerek:onerror="alert(1)
Payload'ımız: " onerror="alert(1)
Çalıştırma ve XSS'i Tetikleme
Hazırladığımız payload'ı URL parametresine enjekte ediyoruz. URL şu hale geliyor: ?art=" onerror="alert(1)
Tarayıcı bunu ayrıştırdığında (parse ettiğinde), HTML şu şekle dönüşür: <img ... src="assets/images/" onerror="alert(1).jpg"/>
(Not: Sondaki
.jpgkısmı payload'ı bozmaz çünkü JavaScript motoru,.jpgyüzünden sözdizimi hatası (syntax error) alıp çökmeden hemen önce, geçerli olanalert(1)fonksiyonunu çoktan çalıştırmış olur.)
assets/images/ geçersiz bir resim yolu olduğundan, tarayıcı resmi yükleyemez. Bu hata durumu anında onerror olay yakalayıcımızı tetikleyerek alert(1) fonksiyonunu çalıştırır.

Ve işte bu kadar! HTML özniteliğini manipüle ederek XSS zafiyetini başarıyla tetikledik.