Skip to content

Commit

Permalink
Merge pull request #175 from codingo/safe-flag
Browse files Browse the repository at this point in the history
Safe-target variable implementation
  • Loading branch information
codingo authored Jun 22, 2023
2 parents 7823e42 + 575582e commit 79b8949
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Interlace/lib/core/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.9.7'
__version__ = '1.9.8'
14 changes: 11 additions & 3 deletions Interlace/lib/core/input.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import functools
import itertools
import os.path
import socket
import struct
import sys
from argparse import ArgumentParser
from io import TextIOWrapper
Expand Down Expand Up @@ -113,12 +111,15 @@ def _pre_process_commands(command_list, task_name=None, is_global_task=True, sil

@staticmethod
def _replace_target_variables_in_commands(tasks, str_targets, ipset_targets):
def starts_and_ends_with(string, character):
return string[0] == character and string[-1] == character
TARGET_VAR = "_target_"
HOST_VAR = "_host_"
CLEANTARGET_VAR = "_cleantarget_"
SAFE_TARGET = "_safe-target_"
for task in tasks:
command = task.name()
if TARGET_VAR in command or HOST_VAR in command:
if TARGET_VAR in command or HOST_VAR in command or SAFE_TARGET in command:
for dirty_target in itertools.chain(str_targets, ipset_targets):
yielded_task = task.clone()
dirty_target = str(dirty_target)
Expand All @@ -129,6 +130,13 @@ def _replace_target_variables_in_commands(tasks, str_targets, ipset_targets):
dirty_target.replace("http://", "").replace(
"https://", "").rstrip("/").replace("/", "-"),
)

if SAFE_TARGET in command:
if (starts_and_ends_with(dirty_target, "'")) or (starts_and_ends_with(dirty_target, '"')):
pass
else:
dirty_target = f"'{dirty_target}'"
yielded_task.replace(SAFE_TARGET, dirty_target)
yield yielded_task
elif CLEANTARGET_VAR in command:
for dirty_target in itertools.chain(str_targets, ipset_targets):
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ Alternatively, you can pass targets in via STDIN and neither -t or -tL will be r
# Variable Replacements
The following variables will be replaced in commands at runtime:

| Variable | Replacement |
|-----------|-------------------------------------------------------------------------|
| \_target\_ | Replaced with the expanded target list that the current thread is running against |
| \_cleantarget\_ | Replaced with target cleanded from http:// or https:// |
| \_host\_ | Works the same as \_target\_, and can be used interchangeably |
| \_output\_ | Replaced with the output folder variable from Interlace |
| \_port\_ | Replaced with the expanded port variable from Interlace |
| \_realport\_ | Replaced with the real port variable from Interlace |
| \_proxy\_ | Replaced with the proxy list from Interlace |
| \_random\_ | Replaced with the randomly chosen file from Interlace |
| Variable | Replacement |
|-----------------|---------------------------------------------------------------------------------------|
| \_target\_ | Replaced with the expanded target list that the current thread is running against |
| \_cleantarget\_ | Replaced with target cleaned from http:// or https:// |
| \_safe-target\_ | Replaced with target automatically quoting for commands, stopping subcommands running |
| \_host\_ | Works the same as \_target\_, and can be used interchangeably |
| \_output\_ | Replaced with the output folder variable from Interlace |
| \_port\_ | Replaced with the expanded port variable from Interlace |
| \_realport\_ | Replaced with the real port variable from Interlace |
| \_proxy\_ | Replaced with the proxy list from Interlace |
| \_random\_ | Replaced with the randomly chosen file from Interlace |

# Advanced Command File Usage
Interlace also makes the use of two additional features for controlling execution flow within a command file: `_blocker_` and `_block:<name>_`. Blockers prevent execution of commands listed after them, until all commands before them have completed, and blocks can be used to force sequential execution of commands listed within a block, for a target.
Expand Down

0 comments on commit 79b8949

Please sign in to comment.