Fileupload firmware update (linux + php)

I would like to perform the firmware update over file upload in my current project.
In my case I'm using Linux + PHP running on my vortex86SX controller.

How to do it ??

  1. Just pack all the updated files together and create a installation script (shell script) called installupdate.sh.
  2. Since shell script created is created on Windows, Linux is having problem to execute the script since it don't understand the additional trail ("\r") for new line. I use this command to remove the "\r" character.

    /bin/cat /tmp/installupdate/installupdate.sh | /bin/tr -d "\r" > /tmp/installupdate
  3. change permission of installation script to enable execute.
  4. run the installation script
  5. remove all the temporary files
Full code :
function installupdate(){
$uploadfile = '/tmp/installupdate.zip';
//phpinfo();
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $uploadfile)) {
$cmd='/bin/mkdir /tmp/installupdate
/bin/unzip -o /tmp/installupdate.zip -d /tmp/installupdate
cd /tmp/installupdate/
/bin/cat /tmp/installupdate/installupdate.sh | /bin/tr -d "\r" > /tmp/installupdate/installupdate.sh
/bin/chmod 777 /tmp/installupdate/installupdate.sh
/bin/sh /tmp/installupdate/installupdate.sh
/bin/rm /tmp/installupdate.zip
/bin/rm /tmp/installupdate -r
'
;
echo "File is valid, and was successfully uploaded.\n";
system("$cmd");
} else {
echo "Possible file upload attack!\n";
}
}

0 comments:

 
Copyright © peyotest