2014-11-21 21:44:55 +00:00
|
|
|
#!/usr/bin/env lua
|
|
|
|
|
|
|
|
-- require ---------------------------------------------------------------------
|
|
|
|
local luasql = require "luasql.sqlite3" -- sqlite module
|
|
|
|
local http = require "socket.http" -- http module
|
|
|
|
local ltn12 = require("ltn12") -- ltn12 module used to convert a sink to a table
|
|
|
|
|
|
|
|
-- functions -------------------------------------------------------------------
|
|
|
|
-- Extract info about the cookie used for newbiecontest connection
|
|
|
|
function extract_cookie(db)
|
|
|
|
|
|
|
|
-- cookie value
|
|
|
|
cursor = db:execute("SELECT value FROM moz_cookies WHERE host LIKE\
|
|
|
|
'%newbiecontest.org%' AND name LIKE '%SMFCookie%'")
|
|
|
|
cookie_value = cursor:fetch(row)
|
|
|
|
cursor:close()
|
|
|
|
|
|
|
|
-- cookie name
|
|
|
|
cursor = db:execute("SELECT name FROM moz_cookies WHERE host LIKE\
|
|
|
|
'%newbiecontest.org%' AND name LIKE '%SMFCookie%'")
|
|
|
|
cookie_name = cursor:fetch(row)
|
|
|
|
cursor:close()
|
|
|
|
|
|
|
|
return cookie_value, cookie_name
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Extract message from http request
|
|
|
|
function extract_message(cookie_name, cookie_value, url)
|
|
|
|
|
|
|
|
-- create the table
|
|
|
|
local t = {}
|
|
|
|
|
|
|
|
-- add the SMF cookie to the header
|
|
|
|
local headers = {
|
2014-11-22 11:18:38 +00:00
|
|
|
["Cookie"] = cookie_name .. "=" .. cookie_value
|
2014-11-21 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- request
|
|
|
|
r = http.request{url = url,
|
|
|
|
headers = headers,
|
|
|
|
sink = ltn12.sink.table(t) -- information goes to the table t
|
|
|
|
}
|
|
|
|
|
|
|
|
-- convert the answer to string
|
|
|
|
string_r = table.concat(t)
|
|
|
|
|
|
|
|
-- extract message and key
|
2014-11-22 11:18:38 +00:00
|
|
|
message = string.match(string_r, '\'([a-z]+)\'')
|
|
|
|
key = string.match(string_r, '\'([0-9]+)\'')
|
2014-11-21 21:44:55 +00:00
|
|
|
|
2014-11-22 11:18:38 +00:00
|
|
|
return message, key
|
2014-11-21 21:44:55 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- decrypt
|
|
|
|
function decrypt(message, key)
|
|
|
|
|
2014-11-22 11:18:38 +00:00
|
|
|
i = 0
|
|
|
|
char_code = 0
|
2014-11-21 21:44:55 +00:00
|
|
|
|
|
|
|
-- create the local table containing the solution
|
2014-11-22 11:18:38 +00:00
|
|
|
local r = {}
|
2014-11-21 21:44:55 +00:00
|
|
|
|
|
|
|
-- for each byte of the message
|
|
|
|
for i = 1, string.len(message), i + 1 do
|
|
|
|
-- extract the char code
|
2014-11-22 11:18:38 +00:00
|
|
|
char_code = string.byte(message, i)
|
2014-11-21 21:44:55 +00:00
|
|
|
-- if it goes behind the "a" move to "z"
|
|
|
|
if (char_code - key < string.byte("a"))
|
|
|
|
then
|
|
|
|
-- here goes the barbary...
|
|
|
|
r[i] = string.char((string.byte("z")) - (key - (char_code -
|
2014-11-22 11:18:38 +00:00
|
|
|
string.byte("a") - 1)))
|
2014-11-21 21:44:55 +00:00
|
|
|
-- if it's not, just do it
|
|
|
|
else
|
2014-11-22 11:18:38 +00:00
|
|
|
r[i] = string.char(char_code - key)
|
2014-11-21 21:44:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-22 11:18:38 +00:00
|
|
|
return table.concat(r)
|
2014-11-21 21:44:55 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Give the response back to the server
|
|
|
|
function send_response(r, url)
|
|
|
|
|
|
|
|
-- crate the table
|
|
|
|
local t = {}
|
|
|
|
|
|
|
|
-- concatenate the url
|
|
|
|
url = url .. "?solution=" .. r
|
|
|
|
|
|
|
|
-- add the SMF cookie to the header
|
|
|
|
local headers = {
|
2014-11-22 11:18:38 +00:00
|
|
|
["Cookie"] = cookie_name .. "=" .. cookie_value
|
2014-11-21 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- send the reply
|
|
|
|
r = http.request{url = url,
|
|
|
|
headers = headers,
|
|
|
|
sink = ltn12.sink.table(t)
|
|
|
|
}
|
|
|
|
|
2014-11-22 11:18:38 +00:00
|
|
|
return table.concat(t) -- return the token
|
2014-11-21 21:44:55 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- main -----------------------------------------------------------------------
|
|
|
|
if table.maxn(arg) < 3
|
|
|
|
then
|
|
|
|
print("Get. The. Fuck. Out")
|
|
|
|
print("[i] Usage : ./crypto.lua file_db url_1 url_2")
|
|
|
|
os.exit()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- sqlite connection
|
|
|
|
env = luasql.sqlite3()
|
|
|
|
conn = env:connect(arg[1])
|
|
|
|
|
|
|
|
cookie_value, cookie_name = extract_cookie(conn)
|
|
|
|
|
2014-11-22 11:18:38 +00:00
|
|
|
message, key = extract_message(cookie_name, cookie_value, arg[2])
|
2014-11-21 21:44:55 +00:00
|
|
|
|
2014-11-22 11:18:38 +00:00
|
|
|
r = decrypt(message, key)
|
2014-11-21 21:44:55 +00:00
|
|
|
|
|
|
|
token = send_response(r, arg[3])
|
|
|
|
|
|
|
|
print(token)
|
|
|
|
|
|
|
|
-- sqlite close
|
|
|
|
env:close()
|
|
|
|
conn:close()
|
|
|
|
|
|
|
|
print("Done.")
|
|
|
|
|