Module: Mailpot::Mail
- Defined in:
- lib/mailpot/mail.rb
Class Method Summary collapse
- .add_message(message) ⇒ Object
- .detect_probe(msg) ⇒ Object
- .forward_probe(msg) ⇒ Object
- .gzdeflate(s) ⇒ Object
-
.initialize ⇒ Object
setup connections etc.
- .store_message(key, value) ⇒ Object
Class Method Details
.add_message(message) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mailpot/mail.rb', line 26 def () if !@initialized initialize end msg = Hash.new msg[:source] = [:source] msg[:sender] = [:sender] msg[:source_ip] = [:ip] msg[:recipients] = [:recipients] msg[:probe] = detect_probe() # we must at this point detect probes because we need them to be sent = Base64.encode64(msg.to_json) = gzdeflate() digest = Digest::MD5.hexdigest() (digest, ) end |
.detect_probe(msg) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/mailpot/mail.rb', line 43 def detect_probe(msg) config = Mailpot.get_config mail = Mail.new(msg[:source]) # First rule we want to detect is when the ip of the honeypot is in the subject if mail.subject.include? config[:smtp_ip] return [true, forward_probe(msg)] end return [false, false] end |
.forward_probe(msg) ⇒ Object
53 54 55 56 57 |
# File 'lib/mailpot/mail.rb', line 53 def forward_probe(msg) Net::SMTP.start('localhost') do | smtp| smtp. msg[:source], msg[:sender], msg[:recipients] end end |
.gzdeflate(s) ⇒ Object
68 69 70 |
# File 'lib/mailpot/mail.rb', line 68 def gzdeflate(s) Zlib::Deflate.new(nil, -Zlib::MAX_WBITS).deflate(s, Zlib::FINISH) end |
.initialize ⇒ Object
setup connections etc
16 17 18 19 20 21 22 23 24 |
# File 'lib/mailpot/mail.rb', line 16 def initialize config = Mailpot.get_config yml = YAML.load_file config[:key_file] @bucket = yml['bucket'] @queue = yml['queue'] @s3 = AWS::S3.new(yml) @sqs = AWS::SQS.new(yml) @initialized = true end |
.store_message(key, value) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/mailpot/mail.rb', line 59 def (key, value) Thread.new { mail = @s3.buckets[@bucket].objects[key] mail.write(value) q = @sqs.queues[@queue] msg = q.(key) } end |