Author Topic: FileSearch 1.0l LUA 5.11 [Strict] [API 2]  (Read 2189 times)

0 Members and 1 Guest are viewing this topic.

Offline Massi

  • Junior Member
  • **
  • Posts: 13
  • Karma: +0/-0
FileSearch 1.0l LUA 5.11 [Strict] [API 2]
« on: 26 May, 2010, 10:52:19 »

Hello ...


Code: [Select]
--[[

FileSearch 1.0l LUA 5.11 [Strict] [API 2]

By Mutor 11/03/07

In as much as I despise scripting this, I am truly tired of
seeing requests for it. My meager efforts at educating the masses
with 'why this shouldn't be done' have failed. Hmm...  Go figure.
My will broken, here is a bad file search for the new PtokaX API.
For LUA 5.1x only

System resources be damned!

- Endlessly searches for preset 'illegal' filenames / strings, one every 15 [or more] seconds.
- Sends search strings in random order until all are used, then list is cycled again.
- Sends a message to online ReportNick or operators in Main chat if file is found [once per user].
- Sends status message to status bar to ReportNick or online Operators.
- Runs garbage collection if memory usage is 20% or more that startup memory usage.


+Changes from 1.0 11/04/07
~Fixed search list cycle method
+Added stop timer once all terms have been used.
+Seach is begun again with new connection or MyINFO string.
+Added OnError messages to Report function

+Changes from 1.0b 11/06/07
+Added user search checking/blocking, per profile. Returns fraudulent result.
+Added log to file function.
~Cleaned up timer function a bit.

+Changes from 1.0c 11/22/07
+Added kick option, after much prompting and against my better judgement.  :P
+Added nick exclusion table [protect by nick].
+Added log entry for kick, MaxLog variable [log file size restriction]

+Changes from 1.0d 12/01/07
+Added choice of kick/ban

+Changes from 1.0e 12/05/07
+Added search results pattern table
+Added additional status/debug messages

+Changes from 1.0f 12/25/07
~Changed search mode to active in order to get SR from all users.

+Changes from 1.0g 12/25/07
+Added user' IP to report and log messages. Requested by [NL]Scooby?
+Added option to always repy in private message. Requested by [NL]Scooby?

+Changes from 1.0g 04/13/08
+Added support for TTH searches. Requested by [NL]Scooby?

+Changes from 1.0i 04/13/08
-Removed support for API 1, now API 2 strict

+Changes from 1.0k 10/17/08
+Added passive search string.
~Changed SendToAll to SendToUser.
+Added Passive string sent to activeusers, active string sent to passive users.
+Search string is only sent to users with > 0 share.
+Added option to always use TTH root in fraudulent search results.
]]

--//-- Start Settings --//--

-- Add your 'illegal' files in the Words array, use quotes and separate with comma.
-- Keep this list as short and it's contents as precise as possible.
-- Consider that many triggers may be found in legitimate files
-- ie. rape will be found in "The Grapes Of Wrath" and the title 'Lolita'
-- is an actual film, not a good one mind you, but it is a film.

-- Search the hub for these strings/hashes...
local Words = {
--TTH strings must begin with TTH: ie:
--"TTH:ZDAWKJRHFFEJ7IOXZ2A5HTTHOY36GQLFAQWTM6Q",
"5PLWTH46UI433BS3BMRYEFUYRXCL2WU7UFIHECQ",
"badfile","stealthdc","r@ygold","animalsex","beastiality","lolita",
"preteen","incest","rape ","underage","childsex","childporn"
}
-- In an effort to be more specific on 'illegal' files,
-- Search results for these patterns. There should be one for each item in the Words table.
-- It may well be the same entry in the words table [ie. exact match] else use Reg-Exp
-- ["string"] = {# of warnings, 0 = disable,*action,"reply string"},
-- *Action to take against user 0=none, 1=kick, 2 = ban
local Patts = {
--TTH patterns should be the exact TTH hash root
["ZDAWKJRHFFEJ7IOXZ2A5HTTHOY36GQLFAQWTM6Q"] = {0,1,"***Badfiles are not allowed here."},
["5PLWTH46UI433BS3BMRYEFUYRXCL2WU7UFIHECQ"] = {0,2,"Anti-Piracy trojan files are not allowed here."},
["stealthdc"] = {0,1,"StealthDC is not allowed here."},
["badfile"] = {3,1,"Badfiles are not allowed here."},
["stealthdc"] = {0,1,"StealthDC is not allowed here."},
["r@ygold"] = {0,1,"Underage pornography is not allowed here."},
["animalsex"] = {0,1,"Beastality content is not allowed here."},
["beastiality"] = {0,1,"Beastality content is not allowed here."},
["preteen"] = {0,1,"Underage pornography is not allowed here."},
["underage"] = {0,1,"Underage pornography is not allowed here."},
["childsex"] = {0,1,"Underage pornography is not allowed here."},
["childporn"] = {0,1,"Underage pornography is not allowed here."},
[".*lolita.*(%.png|%.jpg|%.gif|%.bmp|%.avi|%.wmv|%.xvid|%.mov|%.ogg|%.mp(g|eg|^3))"] = {0,1,"Underage pornography is not allowed here."},
[" *rap(e|ed|ing).*(%.avi|%.wmv|%.xvid|%.mov|%.ogg|%.mp(g|eg|^3))"] = {0,1,"Rape content is not allowed here."},
[" *incest.*(%.png|%.jpg|%.gif|%.bmp|%.avi|%.wmv|%.xvid|%.mov|%.ogg|%.mp(g|eg|^3))"] = {0,1,"Incest content is not allowed here."},
}

-- "BotName" [ "" = hub bot ]
local Bot = "[FileSearch]"
-- Admin's nick / chatroom name for status messages, "" = disable
-- If disabled, report will be sent to all online operators.
local ReportNick = "Mutor"
-- Send extended status information to ReportNick or Operators , true/false
local Verbose = false
-- Reporting level 0=disabled, 1=critical errors, 2=extended status, 3=all messages
local ReportLevel = 3
-- Always report in PM?  true/false
local PmOnly = true
-- Seconds between file searches [should be >= 15 seconds]
local Secs = 15
-- Always use TTH root in fraudulent $SR, true/false
local AlwaysTTH = true
-- Action to take against user 0=none, 1=kick, 2 = ban
local Action = 1
-- Number of warns before Action is taken, when Action > 0. [0 = disable]
local Warns = 3
-- Perm. ban level, used ony if Action = 2 [1 = Nick Ban, 2 = IP Ban, 3 = Nick/IP Ban]
local BanLevel = 1
-- Exclude these users from check/kick
local Exc = {
["Mutor"] = true,
["OtherNick"] = true,
}
-- Maximum permissable size of log file [in bytes]
local MaxLog = 5000
-- Set your profiles permissions here.
-- profile_idx, Allowed to search for illegal files? [0=no 1=yes], "Profile Name"
local Profiles = {
[-1] = {false,"Unregistered User"},
[0] = {true,"Master"},
[1] = {true,"Operator"},
[2] = {true,"Vip"},
[3] = {false,"Registered User"},
}

local ReportProfiles = {
[-1] = {false,"Unregistered User"},
[0] = {true,"Master"},
[1] = {true,"Operator"},
[2] = {false,"Vip"},
[3] = {false,"Registered User"},
}
--//-- End Settings --//--

local T,Tm,Used,Nicks,Log,HubIp,HubUdp = {},0,{},{},""
OnStartup = function()
if Bot == "" then Bot = SetMan.GetString(21) else Core.RegBot(Bot,"","",true) end
if not Core.GetHubIP() and not SetMan.GetBool(43) then SetMan.SetBool(43,true) SetMan.Save() end
HubIp,HubUdp = Core.GetHubIP(),SetMan.GetString(4)
if HubIp and HubUdp then Tm = TmrMan.AddTimer(1000 * Secs) end
collectgarbage("collect")
end

OnTimer = function(Id)
if Id and Id == Tm then
local x,z = ChkWrd(),string.rep("\t",12).."is kicking because:"
if x then
local s,msg,t = Words[x],"Searching user shares for: [ "..x.." ]  ",1
local tth = s:find("^TTH%:")
if tth then t = 9 end
for _,usr in ipairs(Core.GetOnlineUsers()) do
if Core.GetUserValue(usr,16) > 0 then
local s = "$Search "..HubIp..":"..HubUdp.." F?T?0?"..t.."?"..s.."|"
if Core.GetUserValue(usr,10) then
s = "$Search Hub:"..Bot.." F?T?0?"..t.."?"..s.."|"
end
Core.SendToUser(usr,s)
end
end
Core.SendToAll("$Search "..HubIp..":"..HubUdp.." F?T?0?"..t.."?"..s.."|")
if ReportLevel > 1 then Report(msg..s.." ...",msg..s.." ..."..z) else Report(nil,msg..s.." ..."..z) end
end
if ChkNicks() > 0 then
local tm = os.date()
for i,v in pairs(Nicks) do
--Nicks[nick] = {sr,v,Warns}
--["badfile"] = {0,1,"Badfiles are not allowed here."},
local Warns,Action,Response,Warned = v[2][1],v[2][2],v[2][3]
if Action > 0 and not Exc[i] then
local file = string.format("%q",v[1])
local rsn,msg,rpt,wmsg = "Illegal file: "..file,"You are being kicked for "..file..
" in your share. Please remove it before you return. "..Response,
i.." with I.P. ? was kicked for illegal file: "..file,"You have an illegal file your "..
"share: : "..file..". Please remove it. You have [0] warnings left."
local log = "[Kick][I.P.: ? ] User: "..rpt.." - "..tm
local t = Core.GetUser(i)
if t then
if not ChkUsr(t.iProfileNumber) then
rpt = rpt:gsub("?",t.sIP)
log = log:gsub("?",t.sIP)
if Action == 2 then
if Warns > 0 then
v[2][1] = (Warns - 1)
if not Warned then Warned = tostring(v[2][1]) end
wmsg = wmsg:gsub("%b[]","["..Warned.."]")
rpt = rpt:gsub("kicked","warned")
log = log:gsub("%[Kick%]","[Warned]")
Core.SendToUser(t,"<"..Bot.."> "..wmsg.."|")
else
msg = msg:gsub("kicked","banned")
rpt = rpt:gsub("kicked","banned")
log = log:gsub("%[Kick%]","[Ban]")
Core.SendToUser(t,"<"..Bot.."> "..msg.."|")
local BanTab = {
[1] = BanMan.BanNick(t.sNick, rsn, Bot), --Nick Ban
[2] = BanMan.BanIP(t.sIP, rsn, Bot, false), -- IP Ban
[3] = BanMan.Ban(t, rsn, Bot, false), -- Nick/IpBan
}
if not BanTab[BanLevel] then
Report("Banning of "..t.sNick.." has failed.")
end
end
else
if Warns > 0 then
v[2][1] = (Warns - 1)
if not Warned then Warned = tostring(v[2][1]) end
wmsg = wmsg:gsub("%b[]","["..Warned.."]")
rpt = rpt:gsub("kicked","warned")
log = log:gsub("%[Kick%]","[Warned]")
Core.SendToUser(t,"<"..Bot.."> "..wmsg.."|")
else
Core.SendToUser(t,"<"..Bot.."> "..msg.."|")
Core.Kick(t,Bot,rsn)
end
end
if ReportLevel >= 1 then Report(rpt) end
Logger(log)
end
end
end
Nicks[i] = nil
end
end
local count = ChkNicks()
if count == 0 and next(Used) and #Used >= #Words then
TmrMan.RemoveTimer(Tm) Tm = nil
if ReportLevel ==3 then Report("Stopping timer...") end
end
end
end

UserConnected = function(user)
if not Tm then
Tm = TmrMan.AddTimer(1000 * Secs)
if ReportLevel == 3 then Report("FileSearch timer has started again.") end
end
math.randomseed(os.clock())
Used = {}
end
OpConnected,RegConnected,MyINFOArrival = UserConnected,UserConnected,UserConnected

Report = function(msg,sb)
if msg and msg ~= "" then
if ReportNick ~= "" then
local rn = ReportNick
local op = Core.GetUser(rn)
if op then
if PmOnly then Core.SendPmToUser(op,Bot,msg.."|") else Core.SendToUser(op,"<"..Bot.."> "..msg.."|") end
if sb then Core.SendToUser(op,"<"..Bot.."> "..sb.."|") end
else
SendToChat(Bot,msg)
end
else
if PmOnly then Core.SendPmToOps(Bot,msg.."|") else Core.SendToOps("<"..Bot.."> "..msg.."|") end
if sb then Core.SendToOps("<"..Bot.."> "..sb.."|") end
end
end
end

OnError = function(msg) if ReportLevel > 0 then Report(msg) end end
ChkUsr = function(i) if Profiles[i] then return Profiles[i][1] else return false end end
ChkUsed = function(x) for a,b in ipairs(Used) do if b == x then return true end end return false end
ChkNicks = function() local x = 0 for i,_ in pairs(Nicks) do x = x + 1 end return x end

ChkWrd = function()
if next(Used) and #Used >= #Words then
Used = {}
math.randomseed(os.clock())
if ReportLevel ==3 then Report("Word list expended...") end
return nil
end
local x = math.random(#Words)
while ChkUsed(x) do x = math.random(#Words) end
table.insert(Used,x)
local M = collectgarbage("count")
local pct = math.floor(((M/Mem) * 100))
if pct > 120 then collectgarbage("collect") end
return x
end

SearchArrival = function(user, data)
local nick = user.sNick
if not Exc[nick] then
if not ChkUsr(user.iProfile) then
local _,_,s = data:find("([^?]+)|$")
if s then
if ReportLevel == 3 then Report(nick..": "..s) end
for i,v in ipairs(Words) do
if s:lower():find(v:lower()) then
local Send,U,B,H,I,P,X
Send,U,B,X = Core.SendToNick,user.sNick,SetMan.GetString(21),true
H,I,P = SetMan.GetString(0),Core.GetHubIP(),SetMan.GetString(4)
local Res = s..string.char(92)..U..", Illegal string "..
"detected, search disabled."..string.rep("\t",20)
Log = Log.."[Search] User: "..U.."\tPattern: "..string.format("%q",i)..
"\tSearch String: "..string.format("%q",s).."\tI.P.\t"..user.sIP.."\tDate: "..
os.date("%B %d, %Y at: %I:%M")..string.sub(string.lower(os.date("%p")),1,1).."\n"
local msg = "*Illegal file search from: "..U..
". Using I.P: "..user.sIP.." Searched For: "..s..".*"
msg = msg:gsub(" ",string.char(160))
local x,z = 1,string.rep("\t",50).."is kicking because:"
if ReportLevel > 1 then Report(msg,msg..z) end
Logger(Log)
if AlwaysTTH then H = "TTH:ZDAWKJRHFFEJ7IOXZ2A5HTTHOY36GQLFAQWTM6Q" end
return Send(U,"$SR "..B.." "..Res.." 0 0/0"..H.." ("..I..":"..P..")"),X
end
end
end
end
end
end

SRArrival = function(user, data)
local nick = user.sNick
if not Exc[nick] then
if not ChkUsr(user.iProfile) then
if nick and not Nicks[nick] then
local c5 = string.char(5)
local _,_,hash = data:find(c5.."TTH%:(%w+) %(")
local _,_,sr = data:find("^$SR %S+ ([^"..c5.."]+)"..c5)
if sr then
if ReportLevel == 3 then Report("Search result from "..nick..": "..sr) end
for i,v in pairs(Patts) do
local match = false
if hash then
if hash:find(i,1,true) then match = true hash = "\tTTH:"..hash end
else
hash = ""
end
if sr:lower():find(i:lower():gsub("[%p%c]","%%%1")) then match = true end
if match then
if ReportLevel > 1 then
Report(nick.." - responded to an illegal file search for: "..
"["..i:gsub("|","&#124;").."] Matching item: "..sr..hash)
end
Nicks[nick] = {sr,v[3]}
T[i] = T[i] + 1
Log = Log.."[File] User: "..nick.."\tPattern: "..string.format("%q",i)..
"\tFile: "..string.format("%q",sr).."\tI.P.\t"..user.sIP.."\tDate: "..
os.date("%B %d, %Y at: %I:%M")..string.sub(string.lower(os.date("%p")),1,1).."\n"
local msg = "*Illegal file result from "..nick..": "..
sr..hash..". Found [ "..T[i].." ] times this session.*"
msg = msg:gsub(" ",string.char(160))
local z = string.rep("\t",50).."is kicking because:"
if ReportLevel > 1 then Report(msg,msg..z) end
Logger(Log)
break
end
end
end
end
end
end
end
UDPSRArrival = SRArrival

ToArrival = function(user,data)
local _,_,to = data:find("^$To: (%S+) From:")
if to and to:lower() == ReportNick:lower() then
if ReportProfiles[user.iProfile] then
local _,_,msg = data:find("%b<> (.+)|$")
if msg then SendToChat(user.sNick,msg) end
else
return Core.SendPmToNick(user.sNick,ReportNick,"Sorry "..user.sNick..", this chat is for "..
"select profiles only. Your message has not been sent. :("),true
end
end
end

SendToChat = function(nick,msg)
local Tab = Core.GetOnlineUsers()
for _,usr in ipairs(Tab) do
if ReportProfiles[usr.iProfile] then
if usr.sNick:lower() ~= nick:lower() then
Core.SendToNick(usr.sNick,"$To: "..usr.sNick.." From: "..Bot..
" $<"..nick.."> " ..msg.."|")
end
end
end
collectgarbage("collect")
end

Logger = function(str)
local f,e = io.open("FileSearch.log")
if f then
local e = f:seek("end")
f:close()
if e > MaxLog then
f,e = io.open("FileSearch.log","w")
f:write("") f:close()
end
else
if ReportLevel > 0 then local err = e:sub(1,-2) Report(err,err) end
end
f,e = io.open("FileSearch.log","a+")
if f then
f:write(str) f:flush() f:close()
else
if ReportLevel > 0 then local err = e:sub(1,-2) Report(err,err) end
end
Log = ""
end
for i,v in pairs(Patts) do T[i] = 0 end
Secs = math.max(Secs,15)
math.randomseed(os.clock())
Mem = collectgarbage("count")

using this script, I realized that maybe there is something that is not working properly ... known because
while running the script does not find these files user co eo words share ... perhaps because the checks are performed in the past? Ce can improve it?


Thanks ... Best regards ...

Maximilian.

PtokaX forum

FileSearch 1.0l LUA 5.11 [Strict] [API 2]
« on: 26 May, 2010, 10:52:19 »

Offline the-master

  • Triple Ace
  • **
  • Posts: 227
  • Karma: +10/-15
Re: FileSearch 1.0l LUA 5.11 [Strict] [API 2]
« Reply #1 on: 26 May, 2010, 11:55:44 »
do you realy want users checked before they join the hub? ???
editing the script to your own settings and reportnick would perhaps make a difference...
keep on sharing :)
dchub://kickincountryhub.no-ip.org

Offline Massi

  • Junior Member
  • **
  • Posts: 13
  • Karma: +0/-0
Re: FileSearch 1.0l LUA 5.11 [Strict] [API 2]
« Reply #2 on: 26 May, 2010, 13:44:26 »
Hello ...

Maybe I explained evil ... maybe my English is not perfect and I apologize ...

The script works correctly and is set well ... this is not my original settings ...

I know it works because it sends the report to my nick of the checks in pvt ...

But I find that some users share files are not moved in preteen and or discovered by the script ...

Maybe not working properly ... I confirmed?

Thanks... Best regards...

Maximilian.

Offline Massi

  • Junior Member
  • **
  • Posts: 13
  • Karma: +0/-0
Re: FileSearch 1.0l LUA 5.11 [Strict] [API 2]
« Reply #3 on: 27 May, 2010, 07:19:00 »
Thanks...

Maximilian

PtokaX forum

Re: FileSearch 1.0l LUA 5.11 [Strict] [API 2]
« Reply #3 on: 27 May, 2010, 07:19:00 »