We used to edit a payload script via the terminal on an old server.
To ease up and avoid typos I'd like to design a php script that generates the payload, save it to a file and use the built-in FTP functionality in PHP to upload the file to the FTP server and chmod the script to 755.
But my generated payload is not particularly liked by the server. It doesn't run.
#./payload.sh
-sh: ./payload.sh: not found
#
However after doing a simple dos2unix payload.sh
, everything runs fine.
#dos2unix payload.sh
#./payload.sh
[OK] running payload....
#
How can I automatically sculpt my file to avoid needing to dos2unix it every time? I've tried the obvious KISS method:
$contents = str_replace("\r","",$contents);
$contents = trim($contents);
No luck. Script still doesn't run.
So I took a peek into the dos2unix.c and dos2unix.h and found out it was seemingly not all that simple as I thought. There was 800-odd lines of code.
Is there any more simple stuff I can do in PHP? FWIW, I have to admit that for the time being, I've been using manual typed files written in Sublime Text 2 on my Mac. I did try to "Save with Encoding" / "UTF-8" and did select "Unix" as "Line Endings".