Make a Simple Web Client in Lua 04-19-2013, 10:15 PM
#1
Hi friends! 
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.
So, here is the little code:
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
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?
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:
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?):
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!
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:

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.

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() -- 9Let 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
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?

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 80You 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.XXXHmm.. 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!

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
Chill \m/ xD
Chill \m/ xD
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
![[Image: Need-ASP.Net-Expert-with-C2.jpg]](http://axtongroup.com/asp.net-developer/wp-content/uploads/2013/02/Need-ASP.Net-Expert-with-C2.jpg)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
![[Image: Need-ASP.Net-Expert-with-C2.jpg]](http://axtongroup.com/asp.net-developer/wp-content/uploads/2013/02/Need-ASP.Net-Expert-with-C2.jpg)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
Follow me on Twitter @jessehorne27