Use samy to log in, send add friend command, get url. HTTP Header
Live plugin window captured the packet as shown in the figure:
image-20240619220223319
Thus we can know the GET request structure is
http://www.csrflabelgg.com/action/friends/add?friend=id, so now we need
to get Samy’s ID number. We can see the red highlighted part 45 is
Samy’s ID by trying to create a new interface for Samy.
Samy sends Alice an email, inducing Alice to click the malicious link
http://www.csrflabattacker.com/get_csrf.html
image-20240619224208937
Log in to Alice’s account to view the email and access the malicious
webpage, captured the GET request packet adding user id 45, which is
Samy, then check the Activity interface and found that Alice added Samy
as a friend.
Samy sends Alice an email, inducing Alice to click the malicious link
http://www.csrflabattacker.com/post_csrf.html
image-20240619232506107
Log in to Alice’s account, then view and click the link in the
email.
image-20240619232629475
We can see that the About me section was successfully modified, and
the POST request packet was captured, which is consistent with the
phenomenon.
image-20240619232821090image-20240620230509435
Task 3: Implement
Login CSRF Attack
First capture the login request packet, the corresponding request
method is POST, url is http://www.csrflabelgg.com/action/login, the
request form has username and password, both are plaintext.
First enter the directory
/var/www/CSRF/Elgg/vendor/elgg/elgg/engine/classes/Elgg, find the
function gatekeeper() in ActionService.php file and comment out the
return true statement
image-20240620231737340
All 3 attacks failed:
image-20240620232609700
GET request has no token:
image-20240620232620176
POST request has no token:
image-20240620232830171
Login has no token:
image-20240620232359807
Cross-Site
Scripting (XSS) Attack Experiment
First need to switch websites, switch to
http://www.xsslabelgg.com.
Task 1: Steal
Cookie from Victim’s Machine
Use samy to log in, modify samy’s profile. In the About me field,
first click Edit HTML, add the following content:
<script> window.onload = function () { var ts = elgg.security.token.__elgg_ts; var token = elgg.security.token.__elgg_token; var guid = elgg.session.user.guid; fetch('http://www.xsslabelgg.com/action/profile/edit', { credentials: 'include', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: newURLSearchParams({ __elgg_ts: ts, __elgg_token: token, guid: guid, briefdescription: "Samy is my hero", }) }) } </script>
Then, switch to using Alice to log in, open Samy’s homepage from
Alice’s interface to view. Through the HTTP Header Live plugin, it was
found that a POST request to modify brief description has been sent out,
achieving the attack effect. The sent HTTP packet:
image-20240621104726870
Task 3: Construct XSS
Worm
Use samy to log in, modify samy’s profile. In the About me field,
first click Edit HTML, add the following content:
Then, switch to using Alice to log in, open Samy’s homepage from
Alice’s interface to view. Through the HTTP Header Live plugin, it was
found that a POST request to modify brief description has been sent out,
achieving the attack effect. The sent HTTP packet:
image-20240621105412187
Unlike the above, the description field of this POST packet was
modified to the malicious XSS script itself, thus creating
propagability. The specific content of the packet modifying Alice’s
Profile is as follows.
Log in as Boby and access Alice’s profile, can also get the POST
packet modifying the profile and Boby’s introduction was also modified
to the same sentence:
image-20240621111233972image-20240621111431159
Task 4: Defense
Strategy
Only Enable HTMLawed 1.9
Elgg has default defense strategies. The virtual machine has disabled
and commented out the corresponding defense strategies. In fact, the
Elgg web application originally enables a customized security plugin
HTMLawed, which validates user input and removes tags from the input.
This specific plugin is registered to the filter tags function in the
elgg/engine/lib/input.php file. For example, it converts tags like