MCPcopy Create free account
hub / github.com/bvcyber/RedWizard / validate_input

Function validate_input

step-2-create-inventory.py:160–212  ·  view source on GitHub ↗
(input_field, value, hosts_yaml)

Source from the content-addressed store, hash-verified

158 return count
159
160def validate_input(input_field, value, hosts_yaml):
161 IP_ADDRESSES = ['ansible_host', 'relay_host_ip']
162 NUMBER = ['backend_port', 'gophish_admin_port',]
163 STRING = ['identification', 'send_from', 'relay_host', 'dns_beacon_subdomain']
164 NAME = ['name']
165 CAMPAIGN_NAME = ['CampaignName']
166 DOMAIN = ['domain_name']
167 URL = ['nginx_bounce_site']
168
169 try:
170 if input_field in IP_ADDRESSES:
171 IP(value)
172
173 elif input_field in NUMBER:
174 if not value.isdigit():
175 print('Provided value is not a number')
176 return False
177
178 elif input_field in STRING:
179 if (' ' in value) or \
180 ('"' in value) or \
181 ("'" in value) or \
182 ('/' in value) or \
183 ('\\' in value):
184 print('Provided value is not a valid string')
185 return False
186
187 elif input_field in NAME:
188 names = get_all_names(hosts_yaml)
189 if value in names:
190 print('Provided name already exists')
191 return False
192 elif input_field in CAMPAIGN_NAME:
193 if not value.isalnum():
194 print('Provided value is not alphanumeric')
195 return False
196 elif input_field in DOMAIN:
197 if not re.match(r'''
198 (?=^.{,253}$) # max. length 253 chars
199 (?!^.+\.\d+$) # TLD is not fully numerical
200 (?=^[^-.].+[^-.]$) # doesn't start/end with '-' or '.'
201 (?!^.+(\.-|-\.).+$) # levels don't start/end with '-'
202 (?:[a-z\d-] # uses only allowed chars
203 {1,63}(\.|$)) # max. level length 63 chars
204 {2,127} # max. 127 levels
205 ''',value, re.X | re.I):
206 return False
207 elif input_field in URL:
208 if not validators.url(value):
209 return False
210 except:
211 return False
212 return True
213
214###############################################################################
215# Print functions

Callers 1

request_dataFunction · 0.85

Calls 1

get_all_namesFunction · 0.85

Tested by

no test coverage detected