ruby-masscan 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f15780e5572b3c89f6b4a8f275ebd72ef93a895e408dc2bf3456b92442c06e9c
4
- data.tar.gz: cac62c4fd70e73924e82380f4521aaccf929c232863720e617af3cd300393f63
3
+ metadata.gz: 064d7200b60b80a1ed4f0459239235d21f96587a3199833988dd5953728cd168
4
+ data.tar.gz: 619757cb909fcec538c63ef5d37d2cb1f1029509d71e957be9aa6f74726ad4ea
5
5
  SHA512:
6
- metadata.gz: 4cbb1a2dd3f23f28cd729896d12cc5cae1ef153ce9110893e19525fd50842e131bb2559762f823ce86db4aa24b49f509a821df7b75e3b556571d0b9be3195418
7
- data.tar.gz: b17dddd6f06b9fc900a230069fcb07f28a3b62192d6766f197261739d7110f2f6248d5ed8c881cdf3e8668bcefa22fb4dfa8f625d9e78fb26414c67baf6ca5de
6
+ metadata.gz: 9d9fa47ab80653e00c4d3f16b02e1cbe824575d0979b43596f7a52c703b9eda0616882e8bd7effdb77a3f9bfafe40b50043ace08a06f4725b59335dab724fee2
7
+ data.tar.gz: ad559b68f9af88c2c2e1b66711a93b3bceda9962cd0b3f1f478400a0f1dd7d79a7a87eab81eef4ff9c1cca426c135732d05437affb757fdc3d1ebcfc64b681b2
data/ChangeLog.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.2.1 / 2023-03-15
2
+
3
+ * Unescape `\\xXX` hex escaped characters in payload strings parsed from `.list`
4
+ masscan files.
5
+
1
6
  ### 0.2.0 / 2021-11-30
2
7
 
3
8
  * Replaced the `rprogram` dependency with [command_mapper].
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ group :development do
11
11
  gem 'simplecov', '~> 0.7'
12
12
 
13
13
  gem 'kramdown'
14
+ gem 'redcarpet', platform: :mri
14
15
  gem 'yard', '~> 0.9'
15
16
  gem 'yard-spellcheck', require: false
16
17
  end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 Hal Brodigan
1
+ Copyright (c) 2021-2023 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -135,7 +135,7 @@ gem 'ruby-masscan', '~> 0.2'
135
135
 
136
136
  ## License
137
137
 
138
- Copyright (c) 2021 Hal Brodigan
138
+ Copyright (c) 2021-2023 Hal Brodigan
139
139
 
140
140
  See {file:LICENSE.txt} for license information.
141
141
 
@@ -82,6 +82,8 @@ module Masscan
82
82
  #
83
83
  # @see https://github.com/robertdavidgraham/masscan/blob/master/doc/masscan.8.markdown
84
84
  #
85
+ # @since 0.2.0
86
+ #
85
87
  class Command < CommandMapper::Command
86
88
 
87
89
  class PortList < CommandMapper::Types::Num
@@ -64,7 +64,7 @@ module Masscan
64
64
  timestamp: parse_timestamp(timestamp)
65
65
  )
66
66
  elsif line.start_with?('banner ')
67
- type, ip_proto, port, ip, timestamp, app_proto, banner = line.split(' ',7)
67
+ type, ip_proto, port, ip, timestamp, app_proto, payload = line.split(' ',7)
68
68
 
69
69
  yield Banner.new(
70
70
  protocol: parse_ip_protocol(ip_proto),
@@ -72,11 +72,28 @@ module Masscan
72
72
  ip: parse_ip(ip),
73
73
  timestamp: parse_timestamp(timestamp),
74
74
  app_protocol: parse_app_protocol(app_proto),
75
- payload: banner
75
+ payload: parse_payload(payload)
76
76
  )
77
77
  end
78
78
  end
79
79
  end
80
+
81
+ #
82
+ # Parses a payload string and removes any `\\xXX` hex escaped characters.
83
+ #
84
+ # @param [String] payload
85
+ # The payload string to unescape.
86
+ #
87
+ # @return [String]
88
+ # The raw payload string.
89
+ #
90
+ # @api private
91
+ #
92
+ def self.parse_payload(payload)
93
+ payload.gsub(/\\x[0-9a-f]{2}/) do |hex_escape|
94
+ hex_escape[2..].to_i(16).chr
95
+ end
96
+ end
80
97
  end
81
98
  end
82
99
  end
@@ -1,4 +1,4 @@
1
1
  module Masscan
2
2
  # ruby-masscan version
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
data/lib/masscan.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'masscan/command'
2
+ require 'masscan/program'
2
3
  require 'masscan/output_file'
@@ -104,6 +104,31 @@ describe Masscan::Parsers::List do
104
104
  expect(yielded_banner.service).to eq(service_keyword)
105
105
  expect(yielded_banner.payload).to eq(payload)
106
106
  end
107
+
108
+ context "when the payload field contains '\\xXX' hex escaped characters" do
109
+ let(:escaped_payload) do
110
+ "HTTP/1.0 404 Not Found\\x0d\\x0aContent-Type: text/html\\x0d\\x0aDate: Thu, 26 Aug 2021 06:47:52 GMT\\x0d\\x0aServer: ECS (sec/974D)\\x0d\\x0aContent-Length: 345\\x0d\\x0aConnection: close\\x0d\\x0a\\x0d"
111
+ end
112
+ let(:unescaped_payload) do
113
+ "HTTP/1.0 404 Not Found\r\nContent-Type: text/html\r\nDate: Thu, 26 Aug 2021 06:47:52 GMT\r\nServer: ECS (sec/974D)\r\nContent-Length: 345\r\nConnection: close\r\n\r"
114
+ end
115
+
116
+ let(:line) do
117
+ "banner #{protocol} #{port} #{ip} #{timestamp.to_i} #{service_name} #{escaped_payload}"
118
+ end
119
+
120
+ it "must unescape the '\\xXX' hex escaped characters" do
121
+ yielded_records = []
122
+
123
+ subject.parse(io) do |record|
124
+ yielded_records << record
125
+ end
126
+
127
+ yielded_banner = yielded_records.first
128
+
129
+ expect(yielded_banner.payload).to eq(unescaped_payload)
130
+ end
131
+ end
107
132
  end
108
133
  end
109
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-masscan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: command_mapper
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements:
113
113
  - masscan >= 1.0.0
114
- rubygems_version: 3.2.22
114
+ rubygems_version: 3.3.26
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: A Ruby interface to masscan.