I am taking a cyber security class and for an assignment we have to exploit a specific php file and gain some sort of access to the server that it is hosted on. I can set my own $email
and $password
variables as they are set with $_POST
. I believe the only piece of code I can exploit is this.
$email = $_POST['email']
$password = $_POST['password']
....
$accountfile = "./acounts/" . $email
if(!file_exists($accountfile)){
diefooter("unknown email address or password")
}
$fh = fopen($accountfile, "r")
if(!$fh){
diefooter("Cannot open file $accountfile.");
}
$last = fgets($fh);
$first = fgets($fh);
$pass = fgets($fh);
if(strcmp($pass,$password)!=0){
diefooter("wrong email or password.")
}
I know that there are vulnerabilities built into the fopen() function and that I can gain access to the shell with the correct input.
filePath = "/var/ctf/music-copyright/html/cgi-bin/login.php"
shellKode = "exploit@gmail.com\0;echo shell_exec("+'"cat '+filePath+'");'
# payload = {'email':shellKode, 'password':'test'}
testPayload = {'email':'exploit@gmail.com','password':'a'}
r = requests.post(url, data = testPayload)
print(r.text)
I can enter an email into the system but the format is verified before saving. At this point I'm a little lost and not sure what else I can be doing.
fopen()
is the only function in the file I think that can be exploited and I can't think of another place where an exploit may be.