Skip to content

Commit 79b8949

Browse files
authored
Merge pull request #175 from codingo/safe-flag
Safe-target variable implementation
2 parents 7823e42 + 575582e commit 79b8949

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

Interlace/lib/core/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.9.7'
1+
__version__ = '1.9.8'

Interlace/lib/core/input.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import functools
22
import itertools
33
import os.path
4-
import socket
5-
import struct
64
import sys
75
from argparse import ArgumentParser
86
from io import TextIOWrapper
@@ -113,12 +111,15 @@ def _pre_process_commands(command_list, task_name=None, is_global_task=True, sil
113111

114112
@staticmethod
115113
def _replace_target_variables_in_commands(tasks, str_targets, ipset_targets):
114+
def starts_and_ends_with(string, character):
115+
return string[0] == character and string[-1] == character
116116
TARGET_VAR = "_target_"
117117
HOST_VAR = "_host_"
118118
CLEANTARGET_VAR = "_cleantarget_"
119+
SAFE_TARGET = "_safe-target_"
119120
for task in tasks:
120121
command = task.name()
121-
if TARGET_VAR in command or HOST_VAR in command:
122+
if TARGET_VAR in command or HOST_VAR in command or SAFE_TARGET in command:
122123
for dirty_target in itertools.chain(str_targets, ipset_targets):
123124
yielded_task = task.clone()
124125
dirty_target = str(dirty_target)
@@ -129,6 +130,13 @@ def _replace_target_variables_in_commands(tasks, str_targets, ipset_targets):
129130
dirty_target.replace("http://", "").replace(
130131
"https://", "").rstrip("/").replace("/", "-"),
131132
)
133+
134+
if SAFE_TARGET in command:
135+
if (starts_and_ends_with(dirty_target, "'")) or (starts_and_ends_with(dirty_target, '"')):
136+
pass
137+
else:
138+
dirty_target = f"'{dirty_target}'"
139+
yielded_task.replace(SAFE_TARGET, dirty_target)
132140
yield yielded_task
133141
elif CLEANTARGET_VAR in command:
134142
for dirty_target in itertools.chain(str_targets, ipset_targets):

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ Alternatively, you can pass targets in via STDIN and neither -t or -tL will be r
7373
# Variable Replacements
7474
The following variables will be replaced in commands at runtime:
7575

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

8788
# Advanced Command File Usage
8889
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.

0 commit comments

Comments
 (0)