Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify redactindicator script so that it can be used as a transformer #32546

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Packs/CommunityCommonScripts/ReleaseNotes/1_1_6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#### Scripts

##### redactindicator
- Modify the script so that it can be used as a transformer.
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,6 @@
".zuerich": "[.]zuerich",
".zw": "[.]zw"}

text = demisto.args()['indicator']
searchkey = demisto.args().get('searchkey')


def redactIP(ip):
iplist = ip.split(".")
Expand All @@ -1332,35 +1329,50 @@ def redactemail(email):
return newemail


ip = re.compile(r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")
def main():
try:
args = demisto.args()
if not args.get('value') and not args.get('indicator'):
return_error('Must provide either arg "value" or arg "indicator".')
text = args.get('value', args.get('indicator'))
searchkey = demisto.args().get('searchkey')
ip = re.compile(r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")
redactDictBASIC = {"http": "hxxp", "meow": "hxxp", "HTTP": "hxxp"}

redactDict = {}
searchkeyDict = {}
if searchkey is not None:
if len(searchkey) > 1:
Redact_String = "<REDACTED>"
for item in searchkey.split(","):
if (item.startswith("$#=")):
Redact_String = item.split("=")[1]
else:
searchkeyDict.update({item.strip(): Redact_String})
for key, value in searchkeyDict.items():
text = text.replace(str(key).strip(), str(value).strip())

redactDictBASIC = {"http": "hxxp", "meow": "hxxp", "HTTP": "hxxp"}
for item in ip.findall(text):
redactDict.update({item: redactIP(item)})

redactDict = {}
searchkeyDict = {}
if searchkey is not None:
if len(searchkey) > 1:
Redact_String = "<REDACTED>"
for item in searchkey.split(","):
if (item.startswith("$#=")):
Redact_String = item.split("=")[1]
else:
searchkeyDict.update({item.strip(): Redact_String})
for key, value in searchkeyDict.items():
email = re.compile(r'[\w\.-]+@[\w\.-]+')
for item in email.findall(text):
redactDict.update({item: redactemail(item)})
for key, value in redactDict.items():
text = text.replace(str(key).strip(), str(value).strip())
for key, value in redactDictBASIC.items():
text = text.replace(str(key).strip(), str(value).strip())
for key, value in ROOOT_Domain_List.items():
text = text.replace(str(key).strip(), str(value).strip())
output = CommandResults(
outputs_prefix="Redacted_inicator",
outputs=text
)
return_results(output)
except Exception as ex:
demisto.error(traceback.format_exc()) # print the traceback
return_error(f'Failed to execute redactindicator. Error: {str(ex)}')

for item in ip.findall(text):
redactDict.update({item: redactIP(item)})

email = re.compile(r'[\w\.-]+@[\w\.-]+')
for item in email.findall(text):
redactDict.update({item: redactemail(item)})
for key, value in redactDict.items():
text = text.replace(str(key).strip(), str(value).strip())
for key, value in redactDictBASIC.items():
text = text.replace(str(key).strip(), str(value).strip())
for key, value in ROOOT_Domain_List.items():
text = text.replace(str(key).strip(), str(value).strip())
context = demisto.context()
demisto.executeCommand('Set', {'key': "Redacted_inicator", 'value': text})
return_results(text)
if __name__ in ('__main__', '__builtin__', 'builtins'):
main()
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
args:
- description: Indicator to be redacted
- description: Indicator to be redacted.
name: value
- description: 'Indicator to be redacted (can be used instead of ''value'' for backwards compatibility).'
name: indicator
required: true
- description: 'string which should be REDACTED '
- description: 'string which should be REDACTED.'
name: searchkey
comment: Redactindicator can help you to defang/redact any kind of indicator (IPv4, url, domain and email), IP addresses will be in the dotted representation like 8.8.8[.].8, all domains will be example[.]com. Optional you can define a "searchkey" which does not to be case sensitive, which will be replaced as <REDACTED>
comment: Redactindicator can help you to defang/redact any kind of indicator (IPv4, url, domain and email), IP addresses will be in the dotted representation like 8.8.8[.].8, all domains will be example[.]com. Optional you can define a "searchkey" which does not to be case sensitive, which will be replaced as <REDACTED>.
commonfields:
id: redactindicator
version: -1
enabled: true
name: redactindicator
script: '-'
script: ''
subtype: python3
timeout: '0'
type: python
dockerimage: demisto/python3:3.10.12.63474
dockerimage: demisto/python3:3.10.13.86272
runas: DBotWeakRole
fromversion: 6.0.0
tests:
- No tests (auto formatted)
engineinfo: {}
runonce: false
scripttarget: 0
tags:
- transformer
4 changes: 2 additions & 2 deletions Packs/CommunityCommonScripts/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Community Common Scripts",
"description": "A pack that contains community scripts",
"support": "community",
"currentVersion": "1.1.5",
"currentVersion": "1.1.6",
"author": "",
"url": "https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/bd-p/Cortex_XSOAR_Discussions",
"email": "",
Expand All @@ -22,4 +22,4 @@
"marketplacev2"
],
"githubUser": []
}
}