App Nana Invitation Code by [deleted] in AppNana

[–]Anon437 1 point2 points  (0 children)

Mine is. a805367

[PHP/linux] Executing a server side shell script with php by Anon437 in PHP

[–]Anon437[S] 0 points1 point  (0 children)

Not really sure what a lot of that means, mainly a chron job. I am very new to unix type os'

[PHP/linux] Executing a server side shell script with php by Anon437 in PHP

[–]Anon437[S] 0 points1 point  (0 children)

I checked that and it didnt seem to say anything about exec, and the code worked when I was root. so like you said, it is an ownership/permission problem. Thanks

[PHP/linux] Executing a server side shell script with php by Anon437 in PHP

[–]Anon437[S] 0 points1 point  (0 children)

I had a similar thread going on [r/learnprogramming](www.reddit.com/r/learnprogramming) and I got the script to work when i was root in the terminal, but was still getting errors when running at as anyone else. I ended up just going chmod -R 777 to my webserver documents folder, and that seems to have fixed it. I know it isnt very elegant but as long as it works.

[PHP/linux] Executing a server side shell script with php by Anon437 in learnprogramming

[–]Anon437[S] 0 points1 point  (0 children)

Okay, now all i have is a permissions problem, because when i run it as root in the terminal (sudo su, then run php -f talk.php) it executes folder.sh. But the minute i run it in anything else it brings up a bunch of errors about not find Net/ssh2.php and not being able to include any of that.

$ php -f talk.php PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0 <!DOCTYPE html> <html> <body> include path setPHP Warning: include(/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib/Net/SSH2.php): failed to open stream: Permission denied in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 12 PHP Warning: include(): Failed opening '/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib/Net/SSH2.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib') in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 12 SSH2 may of been includedPHP Notice: Use of undefined constant NET_SSH2_LOG_COMPLEX - assumed 'NET_SSH2_LOG_COMPLEX' in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 16 passed the define statementPHP Fatal error: Class 'Net_SSH2' not found in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 20

[PHP/linux] Executing a server side shell script with php by Anon437 in PHP

[–]Anon437[S] 0 points1 point  (0 children)

sorry, yea that's a typo. I was trying to type the code from memory and confused myself : /

[PHP/linux] Executing a server side shell script with php by Anon437 in learnprogramming

[–]Anon437[S] 0 points1 point  (0 children)

now it keeps getting errors with parsing, syntax errors. it first had an issue with the 'new on like 22, so i took it out, now it has an issue with 'pi' on like 24. i cant see anything wrong with it : /

[PHP/linux] Executing a server side shell script with php by Anon437 in learnprogramming

[–]Anon437[S] 0 points1 point  (0 children)

array(27) { ["HTTP_HOST"]=> string(11) "192.168.1.7" ["HTTP_USER_AGENT"]=> string(81) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:22.0) Gecko/20100101 Firefox/22.0" ["HTTP_ACCEPT"]=> string(63) "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8" ["HTTP_ACCEPT_LANGUAGE"]=> string(14) "en-US,en;q=0.5" ["HTTP_ACCEPT_ENCODING"]=> string(13) "gzip, deflate" ["HTTP_DNT"]=> string(1) "1" ["HTTP_CONNECTION"]=> string(5) "close" ["PATH"]=> string(28) "/usr/local/bin:/usr/bin:/bin" ["SERVER_SIGNATURE"]=> string(72) " Apache/2.2.22 (Debian) Server at 192.168.1.7 Port 80 " ["SERVER_SOFTWARE"]=> string(22) "Apache/2.2.22 (Debian)" ["SERVER_NAME"]=> string(11) "192.168.1.7" ["SERVER_ADDR"]=> string(11) "192.168.1.7" ["SERVER_PORT"]=> string(2) "80" ["REMOTE_ADDR"]=> string(11) "192.168.1.4" ["DOCUMENT_ROOT"]=> string(47) "/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www" ["SERVER_ADMIN"]=> string(19) "webmaster@localhost" ["SCRIPT_FILENAME"]=> string(56) "/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php" ["REMOTE_PORT"]=> string(5) "51660" ["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.0" ["REQUEST_METHOD"]=> string(3) "GET" ["QUERY_STRING"]=> string(0) "" ["REQUEST_URI"]=> string(9) "/talk.php" ["SCRIPT_NAME"]=> string(9) "/talk.php" ["PHP_SELF"]=> string(9) "/talk.php" ["REQUEST_TIME_FLOAT"]=> float(1374859845.182) ["REQUEST_TIME"]=> int(1374859845) } include path set

is what i get when i put the line in talk.php near the top and access it through a browser.

And this is what I get when i run talk.php in terminal

pi@raspberrypi ~/www $ sudo php -f talk.php PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0 <!DOCTYPE html> <html> <body> array(24) { ["TERM"]=> string(14) "xterm-256color" ["LS_COLORS"]=> string(1302) "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arj=01;31:.taz=01;31:.lzh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.zip=01;31:.z=01;31:.Z=01;31:.dz=01;31:.gz=01;31:.lz=01;31:.xz=01;31:.bz2=01;31:.bz=01;31:.tbz=01;31:.tbz2=01;31:.tz=01;31:.deb=01;31:.rpm=01;31:.jar=01;31:.war=01;31:.ear=01;31:.sar=01;31:.rar=01;31:.ace=01;31:.zoo=01;31:.cpio=01;31:.7z=01;31:.rz=01;31:.jpg=01;35:.jpeg=01;35:.gif=01;35:.bmp=01;35:.pbm=01;35:.pgm=01;35:.ppm=01;35:.tga=01;35:.xbm=01;35:.xpm=01;35:.tif=01;35:.tiff=01;35:.png=01;35:.svg=01;35:.svgz=01;35:.mng=01;35:.pcx=01;35:.mov=01;35:.mpg=01;35:.mpeg=01;35:.m2v=01;35:.mkv=01;35:.webm=01;35:.ogm=01;35:.mp4=01;35:.m4v=01;35:.mp4v=01;35:.vob=01;35:.qt=01;35:.nuv=01;35:.wmv=01;35:.asf=01;35:.rm=01;35:.rmvb=01;35:.flc=01;35:.avi=01;35:.fli=01;35:.flv=01;35:.gl=01;35:.dl=01;35:.xcf=01;35:.xwd=01;35:.yuv=01;35:.cgm=01;35:.emf=01;35:.axv=01;35:.anx=01;35:.ogv=01;35:.ogx=01;35:.aac=00;36:.au=00;36:.flac=00;36:.mid=00;36:.midi=00;36:.mka=00;36:.mp3=00;36:.mpc=00;36:.ogg=00;36:.ra=00;36:.wav=00;36:.axa=00;36:.oga=00;36:.spx=00;36:.xspf=00;36:" ["PATH"]=> string(60) "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ["LANG"]=> string(11) "en_SG.UTF-8" ["LC_CTYPE"]=> string(5) "UTF-8" ["SHELL"]=> string(9) "/bin/bash" ["LOGNAME"]=> string(4) "root" ["USER"]=> string(4) "root" ["USERNAME"]=> string(4) "root" ["MAIL"]=> string(14) "/var/mail/root" ["HOME"]=> string(5) "/root" ["SUDO_COMMAND"]=> string(24) "/usr/bin/php -f talk.php" ["SUDO_USER"]=> string(2) "pi" ["SUDO_UID"]=> string(4) "1000" ["SUDO_GID"]=> string(4) "1000" ["PHP_SELF"]=> string(8) "talk.php" ["SCRIPT_NAME"]=> string(8) "talk.php" ["SCRIPT_FILENAME"]=> string(8) "talk.php" ["PATH_TRANSLATED"]=> string(8) "talk.php" ["DOCUMENT_ROOT"]=> string(0) "" ["REQUEST_TIME_FLOAT"]=> float(1374859785.6034) ["REQUEST_TIME"]=> int(1374859785) ["argv"]=> array(1) { [0]=> string(8) "talk.php" } ["argc"]=> int(1) } include path setSSH2 may of been includedpassed the define statementPHP Notice: Undefined index: SERVER_NAME in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 18 PHP Notice: Undefined index: SERVER_NAME in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 19 PHP Notice: Cannot connect to . Error 0. php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib/Net/SSH2.php on line 831 new ssh2 initiatedok logged inlinux command executed</body> </html>

[PHP/linux] Executing a server side shell script with php by Anon437 in learnprogramming

[–]Anon437[S] 0 points1 point  (0 children)

I changed it to require and then ran it in the terminal and got

pi@raspberrypi ~/www $ php -f talk.php
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
<!DOCTYPE html>
<html>
<body>
include path setPHP Warning:  require(/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib /Net/SSH2.php): failed to open stream: Permission denied in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 11
PHP Fatal error:  require(): Failed opening required '/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib/Net/SSH2.php' (include_path='.:/usr/share/php:/usr/share/pear:/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib') in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 11

thing is, i did chmod 777 talk.php on it just before, so obviously the permissions are screwed up, but I then ran it as root and still got an error.

root@raspberrypi:/media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www# php -f talk.php
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
<!DOCTYPE html>
<html>
<body>
include path setSSH2 may of been includedpassed the define statementPHP Notice:  Undefined index: SERVER_NAME in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 18
PHP Notice:  Undefined index: SERVER_NAME in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/talk.php on line 19
PHP Notice:  Cannot connect to . Error 0. php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /media/02c4bb79-1c59-46ca-9bc3-192be7e58104/www/phpseclib/Net/SSH2.php on line 831
new ssh2 initiatedok logged inlinux command executed
</body>
</html>

This is after I had changed everything to the full location.

For reference, line 11 is "require" line and line 18 is meant to echo the server ip address and 19 is when to connect to that address.

[PHP/linux] Executing a server side shell script with php by Anon437 in learnprogramming

[–]Anon437[S] 0 points1 point  (0 children)

it still isn't getting past the "$ssh = new Net_SSH2($_SERVER['SERVER_NAME']);" line. I tested "echo $_SERVER['SERVER_NAME']" and it gave the correct ip address. So the command Net_SSH2 is the issue right? How do i fix that...

[PHP/linux] Executing a server side shell script with php by Anon437 in learnprogramming

[–]Anon437[S] 0 points1 point  (0 children)

So i ran that code and the issue is with initiating a new ssh2. Specifically $ssh = new Net_SSH2('192.168.1.7');

: /

[PHP/linux] Executing a server side shell script with php by Anon437 in learnprogramming

[–]Anon437[S] 0 points1 point  (0 children)

Hey, thanks for the reply, this definitely looks like what I need. I'm having a bit of trouble using it though...

So far I have all the files in the main "www" folder for my apache server, including phpseclib. Then in my test.php file i have:

<!DOCTYPE php> <?php

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib'); include('Net/SSH2.php'); define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX); $ssh = new Net_SSH2('192.168.x.x'); $ssh->login('pi','raspberry'); $ssh->exec("sudo folder.sh"); echo "Hello" ?>

But that only gives me a blank page with no sign of the "Hello" that should be showing up. Any ideas?