Skip to content

Commit db1b10f

Browse files
committed
feat: Backtrack
1 parent 91f369d commit db1b10f

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

path_scanner/tasks.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
import subprocess
33

44
from celery import shared_task
5-
from django.db import transaction
65
from django.utils import timezone
76

8-
from common.models import BaseScanJob
97
from .models import PathScanJob, PathScanResult # 确保导入模型
10-
8+
from common.utils import get_scan_job_by_task_id
119

1210
@shared_task(bind=True)
13-
def scan_paths(self, wordlist, url, delay, from_job=None):
11+
def scan_paths(self, wordlist, url, delay, from_job_id=None):
1412
# 确保URL格式正确,移除FUZZ前的斜杠(如果存在)
1513
url = url.replace('/FUZZ', 'FUZZ') # 直接替换'/FUZZ'为'FUZZ'
1614

15+
from_job_instance = None
16+
if from_job_id:
17+
try:
18+
from_job_instance = get_scan_job_by_task_id(from_job_id)
19+
except Exception:
20+
from_job_instance = None
21+
1722
# 创建PathScanJob实例
1823
scan_job = PathScanJob.objects.create(
1924
target=url,
2025
status='R',
2126
task_id=self.request.id,
22-
from_job=from_job,
27+
from_job=from_job_instance,
2328
)
2429

2530
# 构建输出文件名
@@ -29,13 +34,6 @@ def scan_paths(self, wordlist, url, delay, from_job=None):
2934
cmd = f"ffuf -w {wordlist} -u {url} -r -p {delay} -mc all -o {output_file_path} -of json"
3035

3136
try:
32-
# 如果提供了from_job_id,则设置对应from_job的to_job为当前任务
33-
if from_job_id:
34-
with transaction.atomic(): # 确保以下操作在一个事务中
35-
from_job = BaseScanJob.objects.get(task_id=from_job_id)
36-
from_job.to_job = scan_job.task_id
37-
from_job.save()
38-
3937
# 执行ffuf命令
4038
process = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4139

port_scanner/tasks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import os
1+
import re
22
import re
33
import subprocess
4-
import requests
54

5+
import requests
66
from bs4 import BeautifulSoup
77
from celery import shared_task
8-
from django.db import transaction
98
from django.utils import timezone
109

11-
from .models import PortScanJob, Port
1210
from common.utils import get_scan_job_by_task_id
11+
from .models import PortScanJob, Port
12+
1313

1414
@shared_task(bind=True)
1515
def scan_ports(self, target, ports, from_job_id=None):
@@ -18,7 +18,7 @@ def scan_ports(self, target, ports, from_job_id=None):
1818
if from_job_id:
1919
try:
2020
from_job_instance = get_scan_job_by_task_id(from_job_id)
21-
except PortScanJob.DoesNotExist:
21+
except Exception:
2222
from_job_instance = None
2323

2424
# 创建PortScanJob实例,使用找到的from_job_instance

0 commit comments

Comments
 (0)