LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-09-2009, 04:15 PM   #1
redss
Member
 
Registered: Jun 2003
Posts: 168

Rep: Reputation: 16
How to execute binary executable using wget


I can locally execute a shell script that resides on a webserver by piping the script to sh, with the following command:
Code:
wget www.somewhere.com/somefile.sh -O - | sh
Now how can I execute a BINARY executable that resides on a webserver?
 
Old 06-10-2009, 01:21 AM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by redss View Post
I can locally execute a shell script that resides on a webserver by piping the script to sh, with the following command:
Code:
wget www.somewhere.com/somefile.sh -O - | sh
Now how can I execute a BINARY executable that resides on a webserver?
What wrong with
Code:
wget www.somewhere.com/somefile.exe
chnod 755 somefile.exe
./somefile.exe
 
Old 06-10-2009, 12:16 PM   #3
redss
Member
 
Registered: Jun 2003
Posts: 168

Original Poster
Rep: Reputation: 16
That would work, but it's 3 lines as opposed to one line. And the same filename has to be redundantly used 3 times. If there's a way to do it with one command, I want to do it that way, it would look cleaner :-)
 
Old 06-11-2009, 01:27 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by redss View Post
That would work, but it's 3 lines as opposed to one line. And the same filename has to be redundantly used 3 times. If there's a way to do it with one command, I want to do it that way, it would look cleaner :-)
Put it in the script.
Code:
#!/bin/sh
[ $# -ne 1 -o "x$1" = "x" ] && {
   echo "Usage: $0 <url>" 1>&2
   exit 1
}
url=$1
filename=`basename $url`
wget $url
chmod 755 $filename
./$filename
 
Old 06-11-2009, 02:49 AM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
There's a primordial difference. Bash are not executable files per se, they are interpreted by bash, in a similar sense that odt files are interpreted by your word processor. So you can read bytes and pipe them into bash (or any other program, as long as it can use a pipe for input).

Binary files are interpreted by your kernel directly, as long as they are a.out or elf files. So you would need to pipe the binary into the kernel elf loader. If could be theoretically possible to read the bytes from the web and send them directly to a device node that would consume them into the loader. This would illustrate the idea (but it's just an sci-fi example, don't dare to try it):

Code:
wget -O - -q http://wahtever | cat > /dev/elf_loader
# or less graphically, but the same
wget -O - -q http://whatever > /dev/elf_loader
However I have no idea how could that be done, if at all. With a bit of kernel hacking it should be possible, I guess

Last edited by i92guboj; 06-11-2009 at 02:54 AM.
 
Old 06-11-2009, 11:37 AM   #6
redss
Member
 
Registered: Jun 2003
Posts: 168

Original Poster
Rep: Reputation: 16
Ok, so there's no simple way to do it, other than writing a script to do that. Thanks all!
 
Old 03-23-2017, 01:51 PM   #7
0b110100100
LQ Newbie
 
Registered: Mar 2017
Posts: 2

Rep: Reputation: Disabled
Thumbs up

Code:
x=arbitrary.exe; wget http://anysite.any/${x}; chmod +x ${x}; ./${x}; rm ${x}

Last edited by 0b110100100; 03-23-2017 at 01:55 PM.
 
1 members found this post helpful.
Old 03-25-2017, 06:21 AM   #8
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
Cool stuff! *BUT* lookup the 'social error' of NecroPosting ...oooops...

#7 works fine (wget http://127.0.0.1/bin/ls; /lib/ld-linux.so.? ./ls)

@#5: I didn't have a /dev/elf*; I finally found: /lib/ld-linux.so.* needs an actual file. It can't execute a pipe or stdin; it needs to be able to mmap() the [BINARY] file.
(I was -trying- to find a way to wget...| exec - or <STDIN or /proc/$$/fd/0 but couldn't!)

Last edited by Jjanel; 03-25-2017 at 06:30 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't execute an executable, even as sudo. davemar SUSE / openSUSE 2 06-25-2008 06:59 AM
php executable binary apt Programming 4 12-08-2004 08:46 AM
Wget - forcing binary mode? Darklegion Linux - Software 1 08-25-2004 11:24 PM
Why the executable file could not execute? jeson_515 Programming 3 03-14-2004 09:40 PM
Cannot execute executable files without ./ brady9953 Linux - Newbie 3 10-13-2003 03:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration