Skip to content

Commit

Permalink
WIP: defang_ip + defang_uri
Browse files Browse the repository at this point in the history
TODO:
- defang_domain & defang_email
- write tests
- write doc
  • Loading branch information
noraj committed Jan 2, 2023
1 parent 1442104 commit 741a713
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/ctf_party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

# Project internal
require 'ctf_party/base64'
require 'ctf_party/rot'
require 'ctf_party/binary'
require 'ctf_party/case'
require 'ctf_party/cgi'
require 'ctf_party/dec'
require 'ctf_party/defang'
require 'ctf_party/digest'
require 'ctf_party/flag'
require 'ctf_party/hex'
require 'ctf_party/case'
require 'ctf_party/cgi'
require 'ctf_party/binary'
require 'ctf_party/leet'
require 'ctf_party/dec'
require 'ctf_party/misc'
require 'ctf_party/rot'
require 'ctf_party/xor'
39 changes: 39 additions & 0 deletions lib/ctf_party/defang.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'ipaddr'
require 'uri'

class String
def defang_ip
if IPAddr.new(self).ipv4?
gsub('.', '[.]')
elsif IPAddr.new(self).ipv6?
gsub(':', '[:]')
else
self
end
end

def defang_uri
uri = URI(self)
case uri
when URI::HTTP, URI::HTTPS, URI::FTP
uri.scheme = uri.scheme.gsub(/t/i, 'X')
when URI::WS, URI::WSS
uri.scheme.insert(1, 'X')
when URI::LDAP, URI::LDAPS
uri.scheme.insert(2, 'X')
when URI::MailTo
uri.scheme.insert(4, 'X')
end
uri.to_s.gsub('.', '[.]')
end

def defang_domain
skip
end

def defang_email
skip
end
end

0 comments on commit 741a713

Please sign in to comment.