Login Register






Make a Simple Web Client in Lua filter_list
Author
Message
Make a Simple Web Client in Lua #1
Hi friends! Smile

Today I will give you a short (and sweet) tutorial in making a very simple network client with Lua.

You will ask- Why a Network Client?
The answer is- We are hackers and we often need to make network tools for ourselves for running eploits, etc. Wink

So, here is the little code:
Code:
require "socket" -- 1 client = socket.connect(arg[1],arg[2]) -- 2 client:send("GET / HTTP/1.0\r\n\r\n") -- 3 while true do -- 4 s, status, partial = client:receive(1024) -- 5 print (s or partial) -- 6 if status == "closed" then break end -- 7 end -- 8 client:close() -- 9

Let me explain line-by-line:

1: require includes "modules" in a Lua script. Modules are like C Header Files or Perl/Python Modules or .NET Namespaces. Here we include "socket" module since it has all the networking functions that we will use here.

2: In Lua we don't need to declare any variables. Sometimes, local variables can be declared but that's another case. Here we use the "socket" module's "connect" function and pass the program arguments that we pass on the command line. The "arg" table (array) is inbuilt in Lua and we can retrieve command-line args from it like
arg[0] - Program name itself
arg[1] - First argument passed
arg[2] - Second argument passed
arg[..] and so on....
Those who code Perl here- It's like the "ARGV" list.

3: Here we send a GET Request to the server we connected to in the last line. The GET, POST and CONNECT requests are beyond this tutorial (and essential if you want to be anything more than script kiddie Biggrin so go learn!).

4 through 8:
We run a loop receiving & printing any responses the server sends back to our GET request.
Here "status" variable will receive a status that we can check if (and when) the server has closed the request.
The "s" and "partial" variables will receive full or partial response text from the server. So while printing we are determining which one of the two has text and then printing the right one.

9: We close the connection since we are done right! What? You want to send anything else? Biggrin

Now the how should you run and test this script? Just save it in any file with extension "lua" like "myawesomescript.lua" or "TheMotherOfAllExploits.lua" :epic: okay.. and run it on Command Prompt (Windows) or Terminal (Linux) with this kind of command:

Code:
lua NameOfYourScript.lua icanhazip.com 80

You will get a result like this. This website shows your IP address. Since, we are playing with raw responses (h4x0r5 NEED raw responses to hack anything!) we get the HTTP Header along with the IP address in the very bottom (you noticed?):

Code:
HTTP/1.0 200 OK Server: nginx Date: Fri, 19 Apr 2013 20:16:06 GMT Content-Type: text/plain Content-Length: 14 X-RTFM: Learn about this site at http://rkrh.kr/2us and don't abuse the service X-YOU-SHOULD-APPLY-FOR-A-JOB: If you're reading this, apply here: http://rackertalent.com/ X-ICANHAZNODE: dfw.icanhazip.com Connection: close XXX.XXX.XXX.XXX

Hmm.. so that "XXX" stuff is my IP address that I smudged (I don't want to be port scanned or DDoS'd lol) you will see your IP address there.

So, that's it. Thanks for your time! Smile
Here's some links to learn Lua:
http://lua.gts-stolberg.de/en/index.php?uml=1
http://www.phailed.me/2011/02/learn-lua-the-hard-way-1/ <-- Phunny Name :lol:
http://lua-users.org/wiki/LearningLua

Note: Lua is a new language and has many pitfalls. It's like a "building under construction". Do not hesitate "pat the walls with mud" so to say if you get stuck somewhere. If you want to learn something ready-made go learn Perl/Python/VB/C# :lol:

Oh here's a present:
Spoiler:
This code has a HIDDEN VIRUS! YOU ARE INFECTED! OMG! Just Kidding Biggrin Chill \m/ xD
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[Image: Need-ASP.Net-Expert-with-C2.jpg]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Reply

Make a Simple Web Client in Lua #2
Hi friends! Smile

Today I will give you a short (and sweet) tutorial in making a very simple network client with Lua.

You will ask- Why a Network Client?
The answer is- We are hackers and we often need to make network tools for ourselves for running eploits, etc. Wink

So, here is the little code:
Code:
require "socket" -- 1 client = socket.connect(arg[1],arg[2]) -- 2 client:send("GET / HTTP/1.0\r\n\r\n") -- 3 while true do -- 4 s, status, partial = client:receive(1024) -- 5 print (s or partial) -- 6 if status == "closed" then break end -- 7 end -- 8 client:close() -- 9

Let me explain line-by-line:

1: require includes "modules" in a Lua script. Modules are like C Header Files or Perl/Python Modules or .NET Namespaces. Here we include "socket" module since it has all the networking functions that we will use here.

2: In Lua we don't need to declare any variables. Sometimes, local variables can be declared but that's another case. Here we use the "socket" module's "connect" function and pass the program arguments that we pass on the command line. The "arg" table (array) is inbuilt in Lua and we can retrieve command-line args from it like
arg[0] - Program name itself
arg[1] - First argument passed
arg[2] - Second argument passed
arg[..] and so on....
Those who code Perl here- It's like the "ARGV" list.

3: Here we send a GET Request to the server we connected to in the last line. The GET, POST and CONNECT requests are beyond this tutorial (and essential if you want to be anything more than script kiddie Biggrin so go learn!).

4 through 8:
We run a loop receiving & printing any responses the server sends back to our GET request.
Here "status" variable will receive a status that we can check if (and when) the server has closed the request.
The "s" and "partial" variables will receive full or partial response text from the server. So while printing we are determining which one of the two has text and then printing the right one.

9: We close the connection since we are done right! What? You want to send anything else? Biggrin

Now the how should you run and test this script? Just save it in any file with extension "lua" like "myawesomescript.lua" or "TheMotherOfAllExploits.lua" :epic: okay.. and run it on Command Prompt (Windows) or Terminal (Linux) with this kind of command:

Code:
lua NameOfYourScript.lua icanhazip.com 80

You will get a result like this. This website shows your IP address. Since, we are playing with raw responses (h4x0r5 NEED raw responses to hack anything!) we get the HTTP Header along with the IP address in the very bottom (you noticed?):

Code:
HTTP/1.0 200 OK Server: nginx Date: Fri, 19 Apr 2013 20:16:06 GMT Content-Type: text/plain Content-Length: 14 X-RTFM: Learn about this site at http://rkrh.kr/2us and don't abuse the service X-YOU-SHOULD-APPLY-FOR-A-JOB: If you're reading this, apply here: http://rackertalent.com/ X-ICANHAZNODE: dfw.icanhazip.com Connection: close XXX.XXX.XXX.XXX

Hmm.. so that "XXX" stuff is my IP address that I smudged (I don't want to be port scanned or DDoS'd lol) you will see your IP address there.

So, that's it. Thanks for your time! Smile
Here's some links to learn Lua:
http://lua.gts-stolberg.de/en/index.php?uml=1
http://www.phailed.me/2011/02/learn-lua-the-hard-way-1/ <-- Phunny Name :lol:
http://lua-users.org/wiki/LearningLua

Note: Lua is a new language and has many pitfalls. It's like a "building under construction". Do not hesitate "pat the walls with mud" so to say if you get stuck somewhere. If you want to learn something ready-made go learn Perl/Python/VB/C# :lol:

Oh here's a present:
Spoiler:
This code has a HIDDEN VIRUS! YOU ARE INFECTED! OMG! Just Kidding Biggrin Chill \m/ xD
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[Image: Need-ASP.Net-Expert-with-C2.jpg]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Reply

RE: Make a Simple Web Client in Lua #3
Go Lua! Biggrin
Anyhow...Very nice tutorial. I would like to point out to people that you are using the Luasocket library. Luasocket Documentation
Keep up the good work and feel free to contact me about Lua project ideas.
[Image: 2YpkRjy.png] Follow me on Twitter @jessehorne27

Reply

RE: Make a Simple Web Client in Lua #4
Go Lua! Biggrin
Anyhow...Very nice tutorial. I would like to point out to people that you are using the Luasocket library. Luasocket Documentation
Keep up the good work and feel free to contact me about Lua project ideas.
[Image: 2YpkRjy.png] Follow me on Twitter @jessehorne27

Reply

RE: Make a Simple Web Client in Lua #5
Lua looks interesting.

Thanks for this snippet.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: Make a Simple Web Client in Lua #6
Lua looks interesting.

Thanks for this snippet.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply