PHP - Exec() Using Bash Instead Of Sh?
I would like PHP to kick off the following command:
Code: [Select] arp -a|sed 's/ /,/g'>arp.csv I also have an executable makeArpFile.sh: Code: [Select] #!/bin/bash arp -a|sed 's/ /,/g'>arp.csv And I have tried executing it in php with the following: $arp = exec("bash makeArpFile.sh", $output, $exit_code); echo("Last line: " . $arp . "\n"); echo("Output: " . $output . "\n"); echo("Exit Code: " . $exit_code . "\n"); /*returns: Last line: Output: Exit Code: 127 */ I also tried just plain old: $arp = exec("makeArpFile.sh", $output, $exit_code); echo("Last line: " . $arp . "\n"); echo("Output: " . $output . "\n"); echo("Exit Code: " . $exit_code . "\n"); /*returns: Last line: Output: Exit Code: 127 */ I can run plain old arp>arp.txt but I really need it formatted in BSD style (arp -a>arp.txt) in order to be able to parse it properly later. Any thoughts? EDIT: for fun I made a useBash.sh script that executed "bash makeArpFile.sh" still no luck. Similar TutorialsThis is a simple permutation function that i was converting from php:
string_gen(){ declare -a chars=('a' 'b') max=4 let length=${#chars[@]}-1 n=0 combination=" " for i in `seq 0 $max`; do let n=($n*($length))+($length) done remainder=0 for i in `seq 0 $n`; do current=$i combination=" " while [[ $current > 0 ]] do remainder=($current%$length) echo remainder if [ $remainder -eq 0 ]; then combination="$combination"${chars[$length]} else combination="$combination"${chars[$remainder]} current = $current/$length fi done done echo $combination }What is wrong with the syntax? Link to PHP version: http://stackoverflow...o-certain-lengt
First off I want to thank everyone that is involved here in passing on the knowledge. After all that is what its all about. Okay so I want to do a campaign on password awareness and try to capitalize a little off of it. I came across the Breached_Compilation which is 1.4 billion email and plain text passwords. It has bash scripting in it to search and parse out the info from plain text documents which are in folders then prints the results in terminal. The other thing is that it posts the passwords in clear text. How would I obfuscate a portion of the clear text passwords? What would be the best way to integrate this to PHP? I am new to coding in PHP so any help is very much appreciated. Thanks an advance. Here is the Bash script.#!/bin/bash dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) if [ "$1" != "" ]; then letter1=$(echo ${1,,}|cut -b1) if [[ $letter1 == [a-zA-Z0-9] ]]; then if [ -f "$dir/data/$letter1" ]; then grep -ai "^$1" "$dir/data/$letter1" else letter2=$(echo ${1,,}|cut -b2) if [[ $letter2 == [a-zA-Z0-9] ]]; then if [ -f "$dir/data/$letter1/$letter2" ]; then grep -ai "^$1" "$dir/data/$letter1/$letter2" else letter3=$(echo ${1,,}|cut -b3) if [[ $letter3 == [a-zA-Z0-9] ]]; then if [ -f "$dir/data/$letter1/$letter2/$letter3" ]; then grep -ai "^$1" "$dir/data/$letter1/$letter2/$letter3" fi else if [ -f "$dir/data/$letter1/$letter2/symbols" ]; then grep -ai "^$1" "$dir/data/$letter1/$letter2/symbols" fi fi fi else if [ -f "$dir/data/$letter1/symbols" ]; then grep -ai "^$1" "$dir/data/$letter1/symbols" fi fi fi else if [ -f "$dir/data/symbols" ]; then grep -ai "^$1" "$dir/data/symbols" fi fi else echo "[*] Example: ./query name@domain.com" fi
Hello, I am mounting google drive to my raspberry pi with this command from command line; sudo gdfs -o allow_other /var/www/html/gdfs.creds /media/pi/gdrives İt is working from command line, but it is not work when i execute it from web browser. Here php content; shell_exec("sudo gdfs -o allow_other /var/www/html/gdfs.creds /media/pi/gdrives"); and i changed my sudoers file giving permission www-data. here is my sudoers file content # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL www-data ALL=NOPASSWD: ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d Can anyone tell me what i am doing wrong ? Does anyone already fix the bug. I found something interesting in the error_log file this morning
x.x.x.x - - [25/Sep/2014:01:12:34 -0500] "GET /cgi-bin/defaul_p.cgi HTTP/1.0" 404 312 "-" "() { :;}; /bin/ping -c 5 "209.126.230.74"
For those not knowing about this, is a new security hole found in all linux/unix based operating systems that should be patched.
http://arstechnica.c...with-nix-in-it/
I'm trying to make colourized output of bash script in php. So far I have this: <?php $cmd = '/home/thebalk/FiveM/manage.sh restart'; while (@ ob_end_flush()); // end all output buffers if any $proc = popen($cmd, 'r'); echo '<pre>'; while (!feof($proc)) { echo fread($proc, 4096); @ flush(); } echo '</pre>'; // // Converts Bashoutput to colored HTML // function convertBash($cmd) { $dictionary = array( '[1;30m' => '<span style="color:black">', '[1;31m' => '<span style="color:red">', '[1;32m' => '<span style="color:green">', '[1;33m' => '<span style="color:yellow">', '[1;34m' => '<span style="color:blue">', '[1;35m' => '<span style="color:purple">', '[1;36m' => '<span style="color:cyan">', '[1;37m' => '<span style="color:white">', '[m' => '</span>' ); $htmlString = str_replace(array_keys($dictionary), $dictionary, $cmd); return $htmlString; } ?> and my output looks like this: [1;36m BOT:[0;39m THE [1;32m TheBalkanRP-SRV01-test SERVER [0;39m WAS RUNNING [1;36m BOT:[0;39m STOPPING THE [1;32m TheBalkanRP-SRV01-test SERVER [1;36m BOT:[0;39m GTA V SERVER HAS STOPPED [1;36m BOT:[0;39m REMOVING CACHE FOLDER [1;36m BOT:[1;31m CACHE FOLDER HAS BEEN REMOVED [0;39m [1;36m BOT:[0;39m STARTING THE [1;32m TheBalkanRP-SRV01-test [0;39m SERVER [1;36m BOT:[1;32m SERVER HAS STARTED [0;39m I know my function is not connected with the code above but what is the right way to do it? Thank you! Hey y'all. Probably a dumb question here but I'm at a loss. I've got a PHP service script that has an include, written as so: $config = new Config('config/config.json'); The config directory is next to the PHP script and does contain the config.json file, so when I run this from the CLI everything works great. However, I've got about 17 PHP services I need to start and really don't feel like typing them all out, so I've written a shell script that does this: #!bin/bash cd /path/to/my/script /usr/local/bin/php ./my-script.php This does start the service, but it bombs out because it can't find the config.json file. If I change the PHP to $config = new Config('./config/config.json'); it works as expected from the shell script. Updating the files is technically possible, but fraught right now for reasons I can't really get into (sorry). Anybody know what the difference is, or have any ideas on how to get around this? Edited September 5, 2020 by maxxdI have a PHP file in /var/www/html/ called foobar.php with the following content: Quote
<?php
I set the permissions of the foobar.php file to different settings. I set the owner and group of foobar.php and /tmp/output to different values. I tried modifying the httpd.conf file. When I placed this stanza in the httpd.conf file QuoteLoadModule php7_module /usr/lib64/httpd/modules/libphp7.so I could not restart the httpd service. I tried using just QuoteLoadModule php7_module modules/libphp7.so But this failed too. I thought PHP would interpret the file regardless of how I access it (e.g., via a web page and with the php command from a Linux terminal). How do I get PHP to invoke a Bash command when someone visits a .php web page? Hi everyone, i'm trying to get it so when i visit my webpage called start.php it executes the command (/bigbrotherbot start) in the terminal which then should start the process on my linux machine. I'm currently using this code Code: [Select] <?php shell_exec('sudo /bigbrotherbot start'); ?> This script doesn't appear to do anything though. I'm very new to php and would really appreciate the help. P.S the file bigbrotherbot is the bash script which works if i actually go to the terminal myself and type /bigbrotherbot start yet when i try to make the php do it it doesnt do anything. any ideas? I'm trying to open a batch file in php with these contents: Code: [Select] @echo off java -classpath rscd.jar;lib/mina.jar;lib/xpp3.jar;lib/slf4j.jar;lib/xstream.jar;lib/hex-string.jar; org.rscdaemon.server.Server pause My PHP code is simply Code: [Select] $run = "C:\\Users\\Zorian\\Desktop\\EasyRSC\\Server\\run-win.bat"; echo exec("cmd.exe /c " . $run); It should open up a java applet, instead it just echos: Code: [Select] Press any key to continue . . . i have a bash script that i was running with cron jobs: #! /bin/bash start=1000 homedir="/home/alin/NetBeansProjects/Fragger2" numberofprocess=`expr $start + $2` i=$start currentnumber=`ps ax | grep index | grep -c php` case "$1" in start) while [ $i -lt $numberofprocess ] do if [ `ps axo cmd | grep index | grep php | grep -c $i` -lt 1 ] ; then /server/php/bin/php $homedir/index.php $i & fi; i=`expr $i + 1` done ;; stop) while [ $currentnumber -ne 0 ] do kill -9 `ps ax | grep php | grep index | awk {'print $1'} | head -n 1`; currentnumber=`ps ax | grep index | grep -c php` done ;; *) echo "Usage : " $0 "start|stop" ;; esac exit 0 and it was working fine, now i'm tring to make it run from a page . if(isset ($_POST['stop'])){ $conn->update("update `links` set `proccess`=0 "); exec("/home/alin/NetBeansProjects/Fragger2/Trans stop 0"); } if(isset ($_POST['start'])){ if(!preg_match("/^[0-9]+$/", $_POST['proccess'])) echo "proccess should be only a number!"; exec("/home/alin/NetBeansProjects/Fragger2/Trans start ".$_POST['proccess']); } and i don't know why it is not working, i have set for this folder all the permision for this folder "chmod -R 777 /home/alin" it doesn't stop running and i can't figure out why i have to kill the procces from the comand line to stop
I figure I’m doing something basic wrong.
$cmd = “at $wtime $wdate <<< “sftp -a -r -P xxx xxx@xxx.xxx.net:”.$file.” /mnt/TRFR” ; the “at” command is never generated atq returns blank. But if I copy the output of the echo from the web page into bash the “at” job gets created.
What am I missing here? Edited April 9, 2020 by Henry_WhoHi guys! I have a php script that works and outputs info: <?php echo exec("uptime"); ?> and another that doesn't output anything: <?php echo exec("MP4Box"); ?> Why? Hello, I was just seeing if someone could push me in the right direction. I have a form that uploads items to a database and it also includes uploading images to a directory as a part of that. That all works, but I was thinking for security it'd be best not to leave that directory as 0777 for permissions. In researching this I found the exec() function. I'm still figuring out the relation of who the permissions are associated with and why. All I know is if the directory has 0777 for permissions my script works just fine. I was just seeing if using exec to change the permissions during the process of uploading the images and then change back would be cumbersome and leave open other problems (there won't be any user-based input being passed to that) or if that actually would be the way to go for this. Thanks! -Frank Hi all.
I tried to execute command below Hello i am trying to execute a linux program for every line of a textarea Code: [Select] $text = $_POST['links']; $text = htmlspecialchars($_POST['links']); $text = nl2br($text); foreach(explode("\n",$text) as $row) { $result = NULL; $command = 'the command'; exec($command,&$result); echo $result[0]."<br>"; } but this always print the result for last line of text area for example if there are 3 lines it print 2 blanks and 1 result... whats wrong?? Hey guys i am trying to create a small script using exec() to convert PDF files into images ... The script worked well in the past and for some reasons it staped working. exec('"C:\\Program Files\\ImageMagick-6.7.1-Q16\\convert.exe" -verbose -density 150 D:\\Inetpub\\www.goulet.ca\\Pub\\Web\\new\\media\\other\\'.$value.' -quality 100 -sharpen 0x1.0 D:\\Inetpub\\www.goulet.ca\\Pub\\Web\\new\\media\\pdf_flipbook\\'.$value.'\\img.png', $out); the $out var returns an empty array Hi, I have a java file that needs to be executed from my php script, the command I have in it works perfectly when I execute directly in the command line, but when I execute it from php it returns this: array(0) { } I have tested that the exec works by using antiword, which does return results as expected, but its not working for the code below. But I would much rather use apache tika. Also your thoughts on whether this is good practice please. I am using this to extract text from CV's and store that in the db to be able to search through. I need to extract from: pdf, doc, rtf and docx. this is the only tool I have found that can handle them all. your help on the exec problem and any suggestions will be much appreciated. Code: [Select] <?php exec('java -jar /etc/tika-app-1.0.jar -t /var/www/html/cvdatabase/400001.doc', $output); var_dump($output); ?> have a executable binary to which i pass some dynamic values as hostname,host id,server name,server id and a text field value. Now i call this binary using exec or shell_exec functions in PHP to stimulate Command executions as a admin. But i am able to invoke the binary and not able to use psexec service of windows. I get logs and DB entries successfully but i also have a xml push operation in psexec call that is required. the format is like :: exec($url,$output,$return_var); url is the command path with parameters . output is an out param and return is the code on execution this is executed in PHP and i want this binary to generate the same output as done from CLI . Currently i guess it's a permission issue with shell that disallows psexec call. How do i invoke the binary with psexec access outside PHP on command shell I have set access privilege of Powershell to "unrestricted" so that any script can be executed. Still it hangs up somewhere in th script causing problems in copying XML file. Powershell psexec is required in the process and i need to track down the root cause so that php side scripting of binary is successfull. Please let me know about your ideas in fixing this. I am using google and trying examples ,but i havent got any feasible solution. Hope some expert advice can guide me out of this. |