write up ctf by ariafatah
Username: natas11
URL: http://natas11.natas.labs.overthewire.org
key?
cipher = key ^ plain text
key = plain text ^ cipher
<?php
print json_encode(array("showpassword"=>"no", "bgcolor"=>"#ffffff"));
print "\n";
$cookie=base64_decode("HmYkBwozJw4WNyAAFyB1VUcqOE1JZjUIBis7ABdmbU1GIjEJAyIxTRg=");
print $cookie;
print "\n";
function xor_encrypted($in) {
$cipher = json_encode(array( "showpassword"=>"no", "bgcolor"=>"#ffffff"));
$text = $in;
$key = '';
// Iterate through each character
for($i=0;$i<strlen($text);$i++) {
$key .= $text[$i] ^ $cipher[$i % strlen($cipher)];
}
return $key;
}
print xor_encrypted($cookie);
print "\n";
?>
php get_key.php
# 3'7 uUG*8MIf+;fmMF"1 "1M
# eDWoeDWoeDWoeDWoeDWoeDWoeDWoeDWoeDWoeDWoe
# bisa dilihat bahwa perulangan xor nya yaitu eDWo
# jadi kita sudah mengetahui semua variablenya
# key = eDWo
# cipher = eDWoeDWoeDWoeDWoeDWoeDWoeDWoeDWoeDWoeDWoe
# plain = {"showpassword":"no","bgcolor":"#ffffff"}
<?php
$data = array( "showpassword"=>"yes", "bgcolor"=>"#ffffff");
function xor_encrypt($in) {
$key = 'eDWo';
$text = $in;
$outText = '';
// Iterate through each character
for($i=0;$i<strlen($text);$i++) {
$outText .= $text[$i] ^ $key[$i % strlen($key)];
}
return $outText;
}
// print xor_encrypt($data);
print base64_encode(xor_encrypt(json_encode($data)));
print "\n";
?>
php encyrpt.php
HmYkBwozJw4WNyAAFyB1VUc9MhxHaHUNAic4Awo2dVVHZzEJAyIxCUc5
dan ketika saya ubah cookienya pada webnya saya berhasil mendapatkan flagnya
curl "http://natas11.natas.labs.overthewire.org/?bgcolor=%23ffffff" \
-u natas11:UJdqkK1pTu6VLt9UHWAgRZz6sVUZ3lEk \
--cookie "data=HmYkBwozJw4WNyAAFyB1VUc9MhxHaHUNAic4Awo2dVVHZzEJAyIxCUc5"
# The password for natas12 is yZdkjAYZRd3R7tq7T5kXMjMJlOIkzDeB<br>
yZdkjAYZRd3R7tq7T5kXMjMJlOIkzDeB