palinka wrote: ↑2020-03-31 13:34Not sure if it's the latest, but it's still the greatest:
https://www.hmailserver.com/forum/viewt ... 66#p209546

palinka wrote: ↑2020-03-31 13:34Not sure if it's the latest, but it's still the greatest:
https://www.hmailserver.com/forum/viewt ... 66#p209546
Multiple strCategories can be listed? I'm thinking 18/20 and 11/20 are often combined. The "tell" is a dynamic/pool PTR as helo.RvdH wrote: ↑2020-03-30 12:21Code: Select all
' strIP, A valid IPv4 or IPv6 address. (required) ' strCategories, comma separated string with integer values (required) ' few examples: ' 7 - Phishing ' 11 - Email Spam ' 14 - Port Scan ' 15 - Hacking ' 17 - Spoofing ' 18 - Brute-Force ' 20 - Exploited Host ' strCommment, Related information (optional: server logs, timestamps, etc.)
Yup, comma separated, eg: "18,20" or "11,20"
Here... Plus some bonus materialRvdH wrote: ↑2020-03-31 12:46@fjansen04
Make sure you only call ReportToAbuseIPDB(ip address, etc, etc) for that IP address once in a 15 minute timespan, it is a limit by AbuseIPDB.
The 2nd line is apparently a report of the same ip address within this 15 minute timespan an therefor it gives the: Too Many Request error
Could be useful to combine it with SorenR's autoban function, at least autoban the IP for 15 minutes (I use a 1 day autoban)
@SorenR, where is the latest and greatest autoban function?
Code: Select all
'******************************************************************************************************************************
'********** AutoBan stuff **********
'******************************************************************************************************************************
Function AutoBan(sIPAddress, sReason, iDuration, sType) : AutoBan = False
'
' sType can be one of the following;
' "yyyy" Year, "m" Month, "d" Day, "h" Hour, "n" Minute, "s" Second
'
Dim oApp : Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(ADMIN, PASSWORD)
With LockFile(TEMPDIR & "\autoban.lck")
On Error Resume Next
Dim oSecurityRange : Set oSecurityRange = oApp.Settings.SecurityRanges.ItemByName("(" & sReason & ") " & sIPAddress)
If Err.Number = 9 Then
With oApp.Settings.SecurityRanges.Add
.Name = "(" & sReason & ") " & sIPAddress
.LowerIP = sIPAddress
.UpperIP = sIPAddress
.Priority = 20
.Expires = True
.ExpiresTime = DateAdd(sType, iDuration, Now())
.Save
End With
AutoBan = True
Result.Value = 1
End If
On Error GoTo 0
.Close
End With
Set oApp = Nothing
End Function
Function LockFile(strPath)
Const Append = 8
Const Unicode = -1
Dim i
On Error Resume Next
With CreateObject("Scripting.FileSystemObject")
For i = 0 To 30
Err.Clear
Set LockFile = .OpenTextFile(strPath, Append, True, Unicode)
If (Not Err.Number = 70) Then Exit For
Wait(1)
Next
End With
If (Err.Number = 70) Then
EventLog.Write( "ERROR: EventHandlers.vbs" )
EventLog.Write( "File " & strPath & " is locked and timeout was exceeded." )
Err.Clear
ElseIf (Err.Number <> 0) Then
EventLog.Write( "ERROR: EventHandlers.vbs : Function LockFile" )
EventLog.Write( "Error : " & Err.Number )
EventLog.Write( "Error (hex) : 0x" & Hex(Err.Number) )
EventLog.Write( "Source : " & Err.Source )
EventLog.Write( "Description : " & Err.Description )
Err.Clear
End If
On Error GoTo 0
End Function
Function Wait(sec)
With CreateObject("WScript.Shell")
.Run "powershell Start-Sleep -Milliseconds " & Int(sec * 1000), 0, True
End With
End Function
'******************************************************************************************************************************
'********** IP is already banned? (for use via POPFetch or Incoming Relay) **********
'******************************************************************************************************************************
Function isIPBanned(oClient) : isIPBanned = False
Dim a, strIP, strLowerIP, strUpperIP, strRegEx
Dim oApp : Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(ADMIN, PASSWORD)
strIP = INET_NTOA(oClient.IPAddress)
For a = 0 To oApp.Settings.SecurityRanges.Count-1
If (oApp.Settings.SecurityRanges.Item(a).Priority = 20) Then
strLowerIP = INET_NTOA(oApp.Settings.SecurityRanges.Item(a).LowerIP)
strUpperIP = INET_NTOA(oApp.Settings.SecurityRanges.Item(a).UpperIP)
If (strUpperIP >= strIP) And (strIP >= strLowerIP) Then
isIPBanned = True
Set oApp = Nothing
Exit Function
End If
End If
Next
Set oApp = Nothing
End Function
Function INET_NTOA(strIP)
Dim a, i, N : N = 0
a = Split(strIP, ".")
For i = 0 To UBound(a)
N = N + CLng(a(i)) * (256 ^ (3 - i))
Next
INET_NTOA = N
End Function
'******************************************************************************************************************************
'********** CIDR stuff 51.15.0.0/15 **********
'******************************************************************************************************************************
Function CIDRBan(CIDR, sReason, iDuration, sType) : CIDRBan = False
'
' sType can be one of the following;
' "yyyy" Year, "m" Month, "d" Day, "h" Hour, "n" Minute, "s" Second
'
Dim oApp : Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(ADMIN, PASSWORD)
With LockFile(TEMPDIR & "\cidrban.lck")
On Error Resume Next
Dim oSecurityRange : Set oSecurityRange = oApp.Settings.SecurityRanges.ItemByName("(" & sReason & ") " & CIDR)
If Err.Number = 9 Then
With oApp.Settings.SecurityRanges.Add
.Name = "(" & sReason & ") " & CIDR
.LowerIP = CIDR2IP(CIDR, False)
.UpperIP = CIDR2IP(CIDR, True)
.Priority = 20
.Expires = True
.ExpiresTime = DateAdd(sType, iDuration, Now())
.Save
End With
CIDRBan = True
Result.Value = 1
End If
On Error GoTo 0
.Close
End With
Set oApp = Nothing
End Function
Function CIDR2IP(CIDR, high)
Const highs = "11111111111111111111111111111111"
Const lows = "00000000000000000000000000000000"
Dim byte0, byte1, byte2, byte3, mask, bytes, rangelow, rangehigh, iplow, iphigh
byte0 = Dec2Bin(Split(CIDR, ".")(0))
byte1 = Dec2Bin(Split(CIDR, ".")(1))
byte2 = Dec2Bin(Split(CIDR, ".")(2))
byte3 = Dec2Bin(Split(Split(CIDR, ".")(3), "/")(0))
mask = Split(Split(CIDR, ".")(3), "/")(1)
bytes = byte0 & byte1 & byte2 & byte3
rangelow = Left(bytes, mask) & Right(lows, 32 - mask)
rangehigh = Left(bytes, mask) & Right(highs, 32 - mask)
iplow = Bin2IP(Left(bytes, mask) & Right(lows, 32 - mask))
iphigh = Bin2IP(Left(bytes, mask) & Right(highs, 32 - mask))
If high Then
CIDR2IP = iphigh
Else
CIDR2IP = iplow
End If
End Function
'
' Expecting input like 00000000000000000000000000000000
'
Function Bin2IP(strbin)
Dim ip0, ip1, ip2, ip3
ip0 = Bin2Dec(Mid(strbin, 1, 8))
ip1 = Bin2Dec(Mid(strbin, 9, 8))
ip2 = Bin2Dec(Mid(strbin, 17, 8))
ip3 = Bin2Dec(Mid(strbin, 25, 8))
'combines all of the bytes into a single string
Bin2IP = ip0 & "." & ip1 & "." & ip2 & "." & ip3
End Function
'
' Expecting input like 00010101
'
Function Bin2Dec(strbin)
Dim length, dec, x, binval, temp
length = Len(strbin)
dec = 0
For x = 1 To length
binval = 2 ^ (length - x)
temp = Mid(strbin, x, 1)
If temp = "1" Then dec = dec + binval
Next
Bin2Dec = dec
End Function
'
' Expecting input 0 thru 255
'
Function Dec2Bin(dec)
Const maxpower = 7
Const length = 8
Dim bin, x, m
bin = ""
x = cLng(dec)
For m = maxpower To 0 Step -1
If x And (2 ^ m) Then
bin = bin + "1"
Else
bin = bin + "0"
End If
Next
Dec2Bin = bin
End Function
Even with autoban enabled i get the "Too Many Request"error from time to time, some try to hammer in
Code: Select all
8252 "2020-03-31 12:41:39.432" "INFO: ReportToAbuseIPDB: Unauthorized connection attempt from IP address 198.108.67.48 on port 465"
6876 "2020-03-31 12:41:39.463" "WARN: AbuseIPDB Error: Too Many Requests"
9052 "2020-03-31 12:41:40.415" "WARN: AbuseIPDB Error: Too Many Requests"
6248 "2020-03-31 12:41:41.382" "WARN: AbuseIPDB Error: Too Many Requests"
8264 "2020-03-31 12:41:41.382" "WARN: AbuseIPDB Error: Too Many Requests"
5864 "2020-03-31 12:41:41.523" "WARN: AbuseIPDB Error: Too Many Requests"
I ran into that situation with my firewall ban project. Now every ban/reject goes like this:
I'd be WAAAAYYY below that since I already banned a good portion of the spamming world. They don't get second chances with me.RvdH wrote: ↑2020-03-31 20:47My limits are increased after registering a domain and reporting IP's, the daily report/lookup limit is now 5000
https://www.abuseipdb.com/user/40316
Good idea! I already parse the firewall log as part of my firewall ban project, so adding this is a no-brainer. Thanks.FYI: Reports for port 3389 are send using another program
You misunderstood me, of course once you ban them for a longer time.... but what if you disable that firewall ban for a week or month, then you are back at normal ratespalinka wrote: ↑2020-03-31 21:26I'd be WAAAAYYY below that since I already banned a good portion of the spamming world. They don't get second chances with me.RvdH wrote: ↑2020-03-31 20:47My limits are increased after registering a domain and reporting IP's, the daily report/lookup limit is now 5000
https://www.abuseipdb.com/user/40316![]()
I use this service: https://github.com/DigitalRuby/IPBan
That's for sure!
I'll check it out. But... I forgot I have port 3389 closed at the router firewall (access ony via VPN and even then only on a custom portI use this service: https://github.com/DigitalRuby/IPBan
Dude, for real?fjansen04 wrote: ↑2020-04-01 09:36The server I am testing this script on, is low usage so I'm not getting anywhere near the AbuseIPDB limits. Therefore I kept port 25 included after all.
This server is also functioning as backup mx. What I don't understand is that when a perfectly legit message is submitted to be relayed to the primary mx, the originally connecting IP is reported to AbuseIPDB. It even reported a Google IP.
Quick question: First, I assume this means no IP with confidence score < 40 returns TRUE. Correct?
Code: Select all
$IP = "77.40.2.198"
$URICheck = "https://api.abuseipdb.com/api/v2/check"
$URIReport = "https://api.abuseipdb.com/api/v2/report"
$Header = @{
'Key' = 'supersecretkey;
'Accept' = 'application/json';
}
$BodyCheck = @{
'ipAddress' = $IP;
'maxAgeInDays' = '90';
'verbose' = '';
}
$BodyReport = @{
'ip' = $IP;
'categories' = '18,20';
'comment' = '.mari-el.ru Spam Factory';
} | ConvertTo-JSON
<# check #>
$AbuseIPDB = Invoke-RestMethod -Method GET $URICheck -Header $Header -Body $BodyCheck -ContentType 'application/json; charset=utf-8'
$AbuseIPDB.data.abuseConfidenceScore
<# report #>
$AbuseIPDB = Invoke-RestMethod -Method POST $URIReport -Header $Header -Body $BodyReport -ContentType 'application/json; charset=utf-8'
$AbuseIPDB.data.abuseConfidenceScore
Correctpalinka wrote: ↑2020-04-02 03:44RvdH wrote: ↑2020-03-22 13:31Quick question: First, I assume this means no IP with confidence score < 40 returns TRUE. Correct?Code: Select all
.SetMaxConfidenceScore(40)
Code: Select all
public bool BlockEndpoint(string ipAddress)
{
return GetConfidenceScore(ipAddress) >= _maxScore;
}
Me neither...but looks like 40 is a good starting point
Coolpalinka wrote: ↑2020-04-02 03:54By the way, I got it working with powershell.
Not sure what I plan to use it for yet. Bases are pretty much covered with your thing in hMailServer.Code: Select all
$IP = "77.40.2.198" $URICheck = "https://api.abuseipdb.com/api/v2/check" $URIReport = "https://api.abuseipdb.com/api/v2/report" $Header = @{ 'Key' = 'supersecretkey; 'Accept' = 'application/json'; } $BodyCheck = @{ 'ipAddress' = $IP; 'maxAgeInDays' = '90'; 'verbose' = ''; } $BodyReport = @{ 'ip' = $IP; 'categories' = '18,20'; 'comment' = '.mari-el.ru Spam Factory'; } | ConvertTo-JSON <# check #> $AbuseIPDB = Invoke-RestMethod -Method GET $URICheck -Header $Header -Body $BodyCheck -ContentType 'application/json; charset=utf-8' $AbuseIPDB.data.abuseConfidenceScore <# report #> $AbuseIPDB = Invoke-RestMethod -Method POST $URIReport -Header $Header -Body $BodyReport -ContentType 'application/json; charset=utf-8' $AbuseIPDB.data.abuseConfidenceScore
Code: Select all
<#
.SYNOPSIS
AbuseIPDBCheckOrReport.ps1: AbuseIPDB.com Check or Report IP
.DESCRIPTION
AbuseIPDBCheckOrReport.ps1: Powershell script to check or report IP at AbuseIPDB.com
.FUNCTIONALITY
1) Checks IP -> Returns status, abuseConfidenceScore
2) Reports IP -> Returns status, abuseConfidenceScore
.PARAMETER IP
Specifies the IP address to be checked or reported.
.PARAMETER Categories
Specifies the categories of reported IPs. !REQUIRED FOR REPORT IP! See https://www.abuseipdb.com/categories for full list.
.PARAMETER Comment
Specifies the comments to be included with reported IP. Parameter optional.
.NOTES
.EXAMPLE
Check IP:
$CheckIP = & C:\path\to\AbuseIPDBCheckOrReport.ps1 "77.40.61.210"
$CheckIP.Status
$CheckIP.Confidence
Report IP:
$CheckIP = & C:\path\to\AbuseIPDBCheckOrReport.ps1 "77.40.61.210" "11"
$CheckIP.Status
$CheckIP.Confidence
$CheckIP = & C:\path\to\AbuseIPDBCheckOrReport.ps1 "77.40.61.210" "11" "spammer"
$CheckIP.Status
$CheckIP.Confidence
Report IP with error:
$CheckIP = & C:\path\to\AbuseIPDBCheckOrReport.ps1 "127.0.0.2" "11"
$CheckIP.Status
$CheckIP.Confidence
$CheckIP = & C:\path\to\AbuseIPDBCheckOrReport.ps1 "127.0.0.2" "11" "spammer"
$CheckIP.Status
$CheckIP.Confidence
#>
Param(
[Parameter(Mandatory=$True)]
[ValidatePattern("((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))")]
[String]$IP,
[Parameter(Mandatory=$False)]
[AllowEmptyString()]
[String]$Categories,
[Parameter(Mandatory=$False)]
[AllowEmptyString()]
[String]$Comment
)
$Error.Clear()
<### USER VARIABLES ###>
$APIKey = "supersecretkey"
$Header = @{
'Key' = $APIKey;
}
If (([string]::IsNullOrEmpty($Categories)) -and ([string]::IsNullOrEmpty($Categories))){
$URICheck = "https://api.abuseipdb.com/api/v2/check"
$BodyCheck = @{
'ipAddress' = $IP;
'maxAgeInDays' = '90';
'verbose' = '';
}
Try {
$AbuseIPDB = Invoke-RestMethod -Method GET $URICheck -Header $Header -Body $BodyCheck -ContentType 'application/json; charset=utf-8'
$StatusNum = "200"
$ConfidenceScore = $AbuseIPDB.data.abuseConfidenceScore
}
Catch {
$ErrorMessage = $_.Exception.Message
[regex]$RegexErrorNum = "\d{3}"
$StatusNum = ($RegexErrorNum.Matches($ErrorMessage)).Value
}
} Else {
$URIReport = "https://api.abuseipdb.com/api/v2/report"
$BodyReport = @{
'ip' = $IP;
'categories' = $Categories;
'comment' = $Comment;
} | ConvertTo-JSON
Try {
$AbuseIPDB = Invoke-RestMethod -Method POST $URIReport -Header $Header -Body $BodyReport -ContentType 'application/json; charset=utf-8'
$StatusNum = "200"
$ConfidenceScore = $AbuseIPDB.data.abuseConfidenceScore
}
Catch {
$ErrorMessage = $_.Exception.Message
[regex]$RegexErrorNum = "\d{3}"
$StatusNum = ($RegexErrorNum.Matches($ErrorMessage)).Value
}
}
$Response = @{
'Status' = $StatusNum;
'Confidence' = $ConfidenceScore;
}
Return $Response
Maybe you should LOG everything in a way that's easily searchable.mikernet wrote: ↑2020-04-03 18:56Clearly had a brainfart...of course I can just do the check there instead of splitting it up.
It is relevant if you are trying to help someone diagnose why your email server isn't accepting emails from them. Sometimes the sending IP address changes, sometimes they use multiple services to send mail and it is difficult to pin down an IP address, etc. It's good information to have. If you aren't getting email from domain XYZ.com then you can just search your banned IP info for that domain to see if that's the cause.
That's kind of the point. Can't log the email/domain if you cut off the connection before you get that info...
IP is better than nothing if there's a reason associated with it.
Does abuseipdb still works great now? Or are there any better options to lookup malicious IPs? I got a recommendation from a friend of mine about this website ip-address-lookup-v4.com, but I haven't tried it yet. Anyone have used this website to look up an IP?Po-In wrote: ↑2018-05-14 15:09Hi all,
I use the website www.AbuseIPDB.com quite a lot for looking up malicious IP addresses.
I've also created some code that will query the AbuseIPDB API and evaluate the response to reject the connection if reported more than 10 times in the last 30 days.
Please note that you need register at AbuseIPDB to obtain an API key.
Use at your own discretion...
Good luck!
EDIT: UPDATED WORKING VERSION FOLLOWS IN THE SECOND POST. (mod.)
Code: Select all
Sub OnClientConnect(oClient) 'Variables ClientIp = oClient.IpAddress 'Connecting remote IP address ClientPort = oClient.Port 'Port it is connecting to DetectPort = 25 'Variable port to check LocalHost = "127.0.0.1" 'Variable for LocalHost IP address APIkey = "GetYourOwn" 'API key (get your own at AbuseIPDB.Com) APIDays = 30 'Variable AbuseIPDB history in days APICount = 10 'Variable threshold to use for rejecting connections 'Check IP Address with AbuseIPDB API If ClientPort = DetectPort and ClientIp <> LocalHost Then Set objXMLHTTP = CreateObject("msxml2.xmlhttp.6.0") objXMLHTTP.Open "GET", "https://www.abuseipdb.com/check/" & ClientIp & "/json", False objXMLHTTP.setRequestHeader "Content-Type", "application/json" objXMLHTTP.Send "key=" & APIKey & "&days=" & APIDays ResponseText = objXMLHTTP.responseText 'Evaluate response (quick & dirty JSON 'parsing') If ResponseText <> "[]" and InStr(Replace(ResponseText, chr(34),""),"isWhitelisted:true") = 0 then RecordCount = CountString(ResponseText, ClientIp) 'Reject connection and write eventlog If RecordCount > APICount Then Result.Value = 1 EventLog.Write ("AbuseIPDB: IP Address " & ClientIp & " rejected (reported " & RecordCount & " times)") 'Accept connection and write warning in eventlog Else Result.Value = 0 EventLog.Write ("AbuseIPDB: IP Address " & ClientIp & " warning (reported " & RecordCount & " times)") End If End If 'Accept connection because IP address is reported but whitelisted at AbuseIPDB If ResponseText <> "[]" and InStr(Replace(ResponseText, chr(34),""),"isWhitelisted:true") <> 0 then Result.Value = 0 RecordCount = CountString(ResponseText, ClientIp) EventLog.Write ("AbuseIPDB: IP Address " & ClientIp & " whitelisted (reported " & RecordCount & " times)") End If Set objXMLHTTP = Nothing End If End Sub Public Function CountString(VariableString, SearchString) CountString = 0 For x = 1 to len(VariableString) - len(SearchString) If Mid(VariableString,x,len(SearchString)) = SearchString then CountString = CountString +1 End If Next End Function
Well... Not an update of Po-in's script but just to show how it works. The v2 API is quite different both in web calling and how to interpret the JSON data. Also, it won't work pre Windows Server 2008 due to TLS1.0/SSL3.0 is not supported anymore.
Code: Select all
Option Explicit
Include("C:\hMailServer\Events\VbsJson.vbs")
Function Include(sInstFile)
Dim f, s, fso
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If fso.FileExists(sInstFile) Then
Set f = fso.OpenTextFile(sInstFile)
s = f.ReadAll
f.Close
ExecuteGlobal s
End If
On Error GoTo 0
Set f = Nothing
Set fso = Nothing
End Function
Function oAbuseIPDB(strIP, ByRef ReturnCode)
Dim oXML, json
Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
Const APIKEY = "v2 ApiKey"
Const DAYS = 90
Set json = New VbsJson
' On Error Resume Next
Set oXML = CreateObject("Msxml2.ServerXMLHTTP.6.0")
oXML.open "GET", "https://api.abuseipdb.com/api/v2/check?ipAddress=" & strIP & "&maxAgeInDays=" & DAYS & "&verbose", False
oXML.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
oXML.setRequestHeader "Key", ApiKey
oXML.setRequestHeader "Accept", "application/json"
oXML.send
Set oAbuseIPDB = json.Decode(oXML.responsetext)
ReturnCode = oXML.Status
' On Error Goto 0
If (ReturnCode <> 200 ) Then WScript.Echo( "<error> api.ipgeolocation.io lookup failed, error code: " & ReturnCode & " on IP address " & strIP )
End Function
Dim oAbuseIP, oData, oReport, Category, ReturnCode
Set oAbuseIP = oAbuseIPDB("118.25.6.39", ReturnCode)
Set oData = oAbuseIP("data")
WScript.Echo "****"
WScript.Echo "IP address " & oData("ipAddress")
WScript.Echo "totalReports " & oData("totalReports")
WScript.Echo "abuseConfidenceScore " & oData("abuseConfidenceScore")
WScript.Echo "lastReportedAt " & oData("lastReportedAt")
WScript.Echo
For Each oReport In oData("reports")
WScript.Echo "reportedAt " & oReport("reportedAt")
For Each Category In oReport("categories")
WScript.Echo "categories " & Category
Next
WScript.Echo
Next
WScript.Echo "****"
WScript.Quit 0
Code: Select all
{
"data": {
"ipAddress": "118.25.6.39",
"isPublic": true,
"ipVersion": 4,
"isWhitelisted": false,
"abuseConfidenceScore": 100,
"countryCode": "CN",
"countryName": "China",
"usageType": "Data Center/Web Hosting/Transit",
"isp": "Tencent Cloud Computing (Beijing) Co. Ltd",
"domain": "tencent.com",
"hostnames": [],
"totalReports": 1,
"numDistinctUsers": 1,
"lastReportedAt": "2018-12-20T20:55:14+00:00",
"reports": [
{
"reportedAt": "2018-12-20T20:55:14+00:00",
"comment": "Dec 20 20:55:14 srv206 sshd[13937]: Invalid user oracle from 118.25.6.39",
"categories": [
18,
22
],
"reporterId": 1,
"reporterCountryCode": "US",
"reporterCountryName": "United States"
}
]
}
}