Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Convert .sh script into Linux binary

Hi guys

Is it possible to create a executable from a Linux .sh script.
So put the code into a ./

Create a executable without having to put .sh at the end to run it.

Would be great if it's possible to obfuscate/enrypt the code to prevent leaking.

Any help would we appreciated!
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

With my limited understanding of Linux, .exe files will run but only if they contain Linux code. If that is what you mean, are you asking if there is a way to change your .sh script to .exe? I would think there are many conversion programs out there that can handle this, both open source and paid software.
[Image: pia_banner_3.png]
(Aug 10, 2017 03:32 AM)Travelers Wrote:  With my limited understanding of Linux, .exe files will run but only if they contain Linux code. If that is what you mean, are you asking if there is a way to change your .sh script to .exe? I would think there are many conversion programs out there that can handle this, both open source and paid software.

No I want to convert a .sh script to a normal linux binary.

Normally you have to start a sh script like this: ./script.sh
But I want to be able to start it like: ./script

So I need to get rid of the .sh but still be able to run it.

I hope you understand it a little bit better now
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

root@kali:~# nano script

Type the following :

#!/bin/bash

echo 123

CTRL+W

root@kali:~# chmod +x script
root@kali:~# ./script
123

So it works without .sh
Bazinga.
(Aug 10, 2017 03:40 AM)YUGOBOSS Wrote:  No I want to convert a .sh script to a normal linux binary.

Normally you have to start a sh script like this: ./script.sh
But I want to be able to start it like: ./script

So I need to get rid of the .sh but still be able to run it.

I hope you understand it a little bit better now

Yeah, this makes much more since, but I'm not sure I can help. I thought I could at first 🤣

Sorry, bro.
[Image: pia_banner_3.png]
(Aug 10, 2017 03:40 AM)YUGOBOSS Wrote:  No I want to convert a .sh script to a normal linux binary.

Normally you have to start a sh script like this: ./script.sh
But I want to be able to start it like: ./script

So I need to get rid of the .sh but still be able to run it.

I hope you understand it a little bit better now

Rename it, make sure that it starts with a shebang (#!/bin/sh etc) and that it is marked as executable.

Quote:$ cat demo.sh
#!/bin/sh
echo "Hello, World!"
$ ./demo.sh
Hello, World!
$ mv demo.sh demo
$ ./demo
Hello, World!


Why did you need to do this though?




ninja edit Just noticed that you said "Would be great if it's possible to obfuscate/enrypt the code to prevent leaking."

You can use system(3) or execl(3) from a C program to make the calls in your shell script. Then you can encrypt your strings or do whatever kind of obfuscation you want to the program without wrecking anything.
(Aug 10, 2017 03:44 AM)abstractbeanfactory Wrote:  Rename it, make sure that it starts with a shebang (#!/bin/sh etc) and that it is marked as executable.


Why did you need to do this though?




ninja edit Just noticed that you said "Would be great if it's possible to obfuscate/enrypt the code to prevent leaking."

You can use system(3) or execl(3) from a C program to make the calls in your shell script. Then you can encrypt your strings or do whatever kind of obfuscation you want to the program without wrecking anything.

Thanks for all your help guys.

The most important part for me is to obfuscate/encrypt the code to prevent leaking of the source. Can someone explain me this a bit better how to do it or link me to it. I can't find anything really online on how to do it.
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

(Aug 10, 2017 04:23 AM)YUGOBOSS Wrote:  Thanks for all your help guys.

The most important part for me is to obfuscate/encrypt the code to prevent leaking of the source. Can someone explain me this a bit better how to do it or link me to it. I can't find anything really online on how to do it.

man system(3)




There's no way to prevent somebody leaking the source, no matter what you do people will find their way around eventually.

If you just want to stop the average person having a look around, you could base64 encode it and then decode it at execution time and pipe it into bash.

eg.

Quote:$ cat original.sh
#!/bin/bash
echo "hello"
$ echo "echo $(base64 original.sh)" > base64.sh
$bash original.sh | base64 -d | bash
hello


If you wanted any real security, you're best rewriting your script in a native language.
What you're looking for is called "shc" which is shell to C.
Here is a tutorial I found online http://www.thegeekstuff.com/2012/05/encr...ll-script/

I've used shc at work, it comes in handy.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by pottedsyeniteMay 20, 2019 09:46 AM 2 142 May 20, 2019 09:46 AM
Last Post: pottedsyenite
[Python] by Red-LeonardJan 9, 2019 10:12 PM 4 175 Jan 9, 2019 10:12 PM
Last Post: Red-Leonard
[Python] by FrogSquad4Feb 12, 2017 04:41 PM 3 102 Feb 12, 2017 04:41 PM
Last Post: FrogSquad4