Email

Sending Email

sendmail.rb

  1. #!/usr/bin/env ruby
  2. # KING SABRI | @KINGSABRI
  3. #
  4. require 'net/smtp'
  5. def send_mail(smtpsrv, username, password, frmemail, dstemail)
  6. msg = "From: #{frmemail}\n"
  7. msg += "To: #{dstemail}\n"
  8. msg += "Date: #{date}\n"
  9. msg += "Subject: Email Subject\n"
  10. msg += "Content-type: text/html\n\n"
  11. msg += "<strong>winter is coming<br>Hi Jon Snow, Please click to win!</strong>"
  12. begin
  13. Net::SMTP.start(smtpsrv, 25, 'localhost', username, password, :login) do |smtp|
  14. smtp.send_message msg, frmemail, dstemail
  15. end
  16. puts "[+] Email has been sent successfully!"
  17. rescue Exception => e
  18. puts "[!] Failed to send the mail"
  19. puts e
  20. end
  21. end
  22. smtpsrv = ARGV[0]
  23. username = "admin@attacker.zone"
  24. password = "P@ssw0rd"
  25. frmemail = "admin@attacker.zone"
  26. dstemail = "JonSnow@victim.com"
  27. smtpsrv = ARGV[0]
  28. if smtpsrv.nil?
  29. puts "[!] IP address Missing \nruby #{__FILE__}.rb [IP ADDRESS]\n\n"
  30. exit 0
  31. end
  32. send_mail smtpsrv, username, password, frmemail, dstemail

Reading Email

readmail.rb

  1. #!/usr/bin/env ruby
  2. # KING SABRI | @KINGSABRI
  3. #
  4. require 'net/imap'
  5. host = ARGV[0]
  6. if host.nil?
  7. puts "[!] IP address Missing \nruby #{__FILE__}.rb [IP ADDRESS]\n\n"
  8. exit 0
  9. end
  10. username = ARGV[1] || "admin@attacker.zone"
  11. password = ARGV[2] || "P@ssw0rd"
  12. imap = Net::IMAP.new(host, 993, true, nil, false)
  13. imap.login(username, password) # imap.authenticate('LOGIN', username, password)
  14. imap.select('INBOX')
  15. mail_ids = imap.search(['ALL'])
  16. # Read all emails
  17. mail_ids.each do |id|
  18. envelope = imap.fetch(id, "ENVELOPE")[0].attr["ENVELOPE"]
  19. puts "[+] Reading message, Subject: #{envelope.subject}"
  20. puts imap.fetch(id,'BODY[TEXT]')[0].attr['BODY[TEXT]']
  21. end
  22. # Delete all emails
  23. # mail_ids.each do |id|
  24. # envelope = imap.fetch(id, "ENVELOPE")[0].attr["ENVELOPE"]
  25. # puts "[+] Deleting message, Subject: #{envelope.subject}"
  26. # imap.store(id, '+FLAGS', [:Deleted]) # Deletes forever No trash!
  27. # end
  28. imap.close
  29. imap.logout
  30. imap.disconnect