project-honeypot2 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6f20a0fb494a34ce5f43d1857db64cc9cf199e50a1d7d36a1a2d874ec67da797
4
+ data.tar.gz: 14dbc23b7c5d184df0388604d79516a8c004ad357cd3ef63d08bbafbe06f6ffc
5
+ SHA512:
6
+ metadata.gz: acff98b758143d37d25d723b675cddc8133b8b204aa43ac07d3ec6956218f086d600b125de07cade79db5d168554d084c24eff1dcb073bb7eb760c708f5eee34
7
+ data.tar.gz: 6109454bbc10f74d78e9cb7e4081f24946423ca251968a70c24fe9e0ee0565fc27562b6956e7180919ed54b089f2a2dff343238bc1d0f0e2135b637dced7d507
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Charles Max Wood chuck@teachmetocode.com
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,80 @@
1
+ = Project Honeypot
2
+
3
+ Project Honeypot is a programmatic interface to the Project Honeypot HTTP:BL service for identifying suspicious ip addresses.
4
+ This Gem was built to filter out spammers on http://www.tweetburner.com.
5
+
6
+ It is a handy thing to be able to identify spammers, harvesters, and other suspicious IP addresses if you're worried about who might be abusing your service.
7
+
8
+ = Requirements
9
+
10
+ This Gem requires that you have an Http:BL API key from Project Honeypot. You can get one at http://www.projecthoneypot.org/
11
+
12
+ = Usage
13
+
14
+ Add 'project-honeypot2' to your Gemfile.
15
+
16
+ HTTP:BL lookups through Project Honeypot result in a Url object that gives you the risk score, last activity, and types of offenses the ip address is listed for.
17
+
18
+ The score is worse the higher it is and the last_activity is in days.
19
+
20
+ == Example #1: Suspicious IP Address
21
+
22
+ Given an api key of "abcdefghijkl"
23
+
24
+ @listing = ProjectHoneypot.lookup("abcdefghijkl", "192.168.1.1")
25
+ @listing.safe?
26
+ # => false
27
+
28
+ @listing.ip_address
29
+ # => "192.168.1.1"
30
+
31
+ @listing.score
32
+ # => 63
33
+
34
+ @listing.last_activity
35
+ # => 1
36
+
37
+ @listing.offenses
38
+ # => [:comment_spammer, :suspicious]
39
+
40
+ @listing.comment_spammer?
41
+ # => true
42
+
43
+ @listing.suspicious?
44
+ # => true
45
+
46
+ @listing.harvester?
47
+ # => false
48
+
49
+ == Example #2: Safe IP Address
50
+
51
+ @listing = ProjectHoneypot.lookup("abcdefghijkl", "192.168.1.1")
52
+ @listing.safe?
53
+ # => true
54
+
55
+ @listing.ip_address
56
+ # => "192.168.1.1"
57
+
58
+ @listing.score
59
+ # => 0
60
+
61
+ @listing.last_activity
62
+ # => nil
63
+
64
+ @listing.offenses
65
+ # => []
66
+
67
+ @listing.comment_spammer?
68
+ # => false
69
+
70
+ @listing.suspicious?
71
+ # => false
72
+
73
+ @listing.harvester?
74
+ # => false
75
+
76
+ = To Do Items
77
+
78
+ - Cache Responses from Project Honeypot
79
+ - Allow 'safe?' to be configurable (algorithm based on recency and severity(score))
80
+ - A .yml config file
@@ -0,0 +1,10 @@
1
+ require 'net/dns'
2
+ require File.dirname(__FILE__) + "/project_honeypot/url.rb"
3
+ require File.dirname(__FILE__) + "/project_honeypot/base.rb"
4
+
5
+ module ProjectHoneypot
6
+ def self.lookup(api_key, url)
7
+ searcher = Base.new(api_key)
8
+ searcher.lookup(url)
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ module ProjectHoneypot
2
+ class Base
3
+ def initialize(api_key)
4
+ @api_key = api_key
5
+ end
6
+
7
+ def lookup(ip_address)
8
+ ip_address = url_to_ip(ip_address)
9
+ reversed_ip = ip_address.split(".").reverse.join(".")
10
+ honeypot_score = extract_ip_address(Net::DNS::Resolver.start("#{@api_key}.#{reversed_ip}.dnsbl.httpbl.org"))
11
+ Url.new(ip_address, honeypot_score)
12
+ end
13
+
14
+ private
15
+
16
+ def url_to_ip(url)
17
+ return url if url.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)
18
+ extract_ip_address(Net::DNS::Resolver.start(url))
19
+ end
20
+
21
+ def extract_ip_address(dns_response)
22
+ dns_response.answer.first.to_s.split.last
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,52 @@
1
+ module ProjectHoneypot
2
+ class Url
3
+ attr_reader :ip_address, :last_activity, :score, :offenses
4
+ def initialize(ip_address, honeypot_response)
5
+ @ip_address = ip_address
6
+ @safe = honeypot_response.nil?
7
+ process_score(honeypot_response)
8
+ end
9
+
10
+ def safe?
11
+ @safe
12
+ end
13
+
14
+ def comment_spammer?
15
+ @offenses.include?(:comment_spammer)
16
+ end
17
+
18
+ def harvester?
19
+ @offenses.include?(:harvester)
20
+ end
21
+
22
+ def suspicious?
23
+ @offenses.include?(:suspicious)
24
+ end
25
+
26
+ private
27
+
28
+ def process_score(honeypot_response)
29
+ if honeypot_response.nil?
30
+ @last_activity = nil
31
+ @score = 0
32
+ @offenses = []
33
+ else
34
+ hp_array = honeypot_response.split(".")
35
+ @last_activity = hp_array[1].to_i
36
+ @score = hp_array[2].to_i
37
+ @offenses = set_offenses(hp_array[3])
38
+ end
39
+ end
40
+
41
+ def set_offenses(offense_code)
42
+ offense_code = offense_code.to_i
43
+ offenses = []
44
+ offenses << :comment_spammer if offense_code/4 == 1
45
+ offense_code = offense_code % 4
46
+ offenses << :harvester if offense_code/2 == 1
47
+ offense_code = offense_code % 2
48
+ offenses << :suspicious if offense_code == 1
49
+ offenses
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: project-honeypot2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Charles Max Wood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-dns2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Project-Honeypot provides a programatic interface to the Project Honeypot
28
+ services. It can be used to identify spammers, bogus commenters, and harvesters.
29
+ You will need a FREE api key from http://projecthoneypot.org
30
+ email: chuck@teachmetocode.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.rdoc
37
+ - lib/project-honeypot.rb
38
+ - lib/project_honeypot/base.rb
39
+ - lib/project_honeypot/url.rb
40
+ homepage: http://teachmetocode.com/
41
+ licenses: []
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.7.7
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Project-Honeypot provides a programatic interface to the Project Honeypot
63
+ services.
64
+ test_files: []