Skip to content

Commit 1b07ada

Browse files
authored
Merge pull request #56 from tristanlatr/Show-wpscan-version
Show wpscan version
2 parents 1596206 + 92b046c commit 1b07ada

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

tests/notification_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_send_report(self):
5151
"wpscan_output":"This is real%s"%(s)
5252
}
5353

54-
wpwatcher.scanner.mail._send_report(report, email_to='test', wpscan_command= 'just testing')
54+
wpwatcher.scanner.mail._send_report(report, email_to='test', wpscan_command= 'just testing', wpscan_version='1.2.3')
5555

5656
# self.assertEqual(report['fixed'], [], "Fixed item wasn't remove after email sent")
5757
# self.assertNotEqual(report['last_email'], None)

wpwatcher/email.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def notify(
5757
wp_site: Dict[str, Any],
5858
wp_report: Dict[str, Any],
5959
last_wp_report: Optional[Dict[str, Any]],
60-
wpscan_command: str,
60+
wpscan_command: str, wpscan_version:str,
6161
) -> bool:
6262
"""Email recipients if match `should_notify` conditions"""
6363
if self.should_notify(wp_report, last_wp_report):
64-
self.send_report(wp_site, wp_report, wpscan_command)
64+
self.send_report(wp_site, wp_report, wpscan_command, wpscan_version)
6565
return True
6666
else:
6767
return False
@@ -83,7 +83,7 @@ def _send_mail(self, message: MIMEMultipart, email_to: List[str]) -> None:
8383

8484
# Send email report with status and timestamp
8585
def _send_report(
86-
self, wp_report: Dict[str, Any], email_to: List[str], wpscan_command: str
86+
self, wp_report: Dict[str, Any], email_to: List[str], wpscan_command: str, wpscan_version:str
8787
) -> None:
8888
"""Build MIME message based on report and call send_mail"""
8989

@@ -96,7 +96,7 @@ def _send_report(
9696
message["To"] = ",".join(email_to)
9797

9898
# Email body
99-
body = self.build_message(wp_report, wpscan_command)
99+
body = self.build_message(wp_report, wpscan_command, wpscan_version)
100100
if self.use_monospace_font:
101101
body = (
102102
f'<font face="Courier New, Courier, monospace" size="-1">{body}</font>'
@@ -187,7 +187,7 @@ def should_notify(
187187
return should
188188

189189
def send_report(
190-
self, wp_site: Dict[str, Any], wp_report: Dict[str, Any], wpscan_command: str
190+
self, wp_site: Dict[str, Any], wp_report: Dict[str, Any], wpscan_command: str, wpscan_version:str
191191
) -> bool:
192192
"""Sending the report"""
193193
# Send the report to
@@ -206,11 +206,11 @@ def send_report(
206206
time.sleep(0.01)
207207

208208
with self._mail_lock:
209-
self._send_report(wp_report, to, wpscan_command)
209+
self._send_report(wp_report, to, wpscan_command, wpscan_version)
210210
return True
211211

212212
@staticmethod
213-
def build_message(wp_report: Dict[str, Any], wpscan_command: str) -> str:
213+
def build_message(wp_report: Dict[str, Any], wpscan_command: str, wpscan_version:str) -> str:
214214
"""Build mail message text base on report and warnngs and info switch"""
215215

216216
message = (
@@ -228,6 +228,7 @@ def build_message(wp_report: Dict[str, Any], wpscan_command: str) -> str:
228228
content=message,
229229
wpwatcher_version=__version__,
230230
wpscan_command=wpscan_command,
231+
wpscan_version=wpscan_version
231232
)
232233

233234

@@ -363,7 +364,7 @@ def build_message(wp_report: Dict[str, Any], wpscan_command: str) -> str:
363364
<tr>
364365
<td class="content-block powered-by" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; font-size: 12px; color: #999999; text-align: center;">
365366
Automating WPscan to scan and report vulnerable Wordpress sites <br/>
366-
<a href="https://github.com/tristanlatr/WPWatcher" style="color: #999999; text-align: center; text-decoration: none;">WPWatcher version $wpwatcher_version </a> <br />
367+
<a href="https://github.com/tristanlatr/WPWatcher" style="color: #999999; text-align: center; text-decoration: none;">WPWatcher version $wpwatcher_version </a> - WPScan version $wpscan_version <br />
367368
</td>
368369
</tr>
369370
</table>

wpwatcher/scan.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ def scan_site(
257257
# Notify recepients if match triggers
258258
if self.mail.notify(
259259
wp_site, wp_report,
260-
last_wp_report, wpscan_command=wpscan_command
260+
last_wp_report,
261+
wpscan_command=wpscan_command,
262+
wpscan_version=self.wpscan._wpscan_version or '??',
261263
):
262264
# Store report time
263265
wp_report["last_email"] = wp_report["datetime"]

wpwatcher/wpscan.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class WPScanWrapper:
3232

3333

3434
_NO_VAL = datetime(year=2000, month=1, day=1)
35+
_NO_VERSION = '0.0.0'
36+
3537
def __init__(self, wpscan_path: str, scan_timeout: Optional[timedelta] = None,
3638
api_limit_wait: bool = False, follow_redirect: bool = False) -> None:
3739
"""
@@ -47,6 +49,7 @@ def __init__(self, wpscan_path: str, scan_timeout: Optional[timedelta] = None,
4749

4850
self._update_lock: threading.Lock = threading.Lock()
4951
self._lazy_last_db_update: Optional[datetime] = self._NO_VAL
52+
self._lazy_wpscan_version: Optional[str] = None
5053

5154
self._api_limit_wait = api_limit_wait
5255
self._follow_redirect = follow_redirect
@@ -103,11 +106,17 @@ def _wait_all_wpscan_process(self) -> None:
103106
@property
104107
def _last_db_update(self) -> Optional[datetime]:
105108
if self._lazy_last_db_update == self._NO_VAL:
106-
self._lazy_last_db_update = self._get_last_db_update()
109+
self._init_lazy_attributes()
107110
return self._lazy_last_db_update
111+
112+
@property
113+
def _wpscan_version(self) -> Optional[str]:
114+
if self._lazy_wpscan_version == self._NO_VERSION:
115+
self._init_lazy_attributes()
116+
return self._lazy_wpscan_version
108117

109118

110-
def _get_last_db_update(self) -> Optional[datetime]:
119+
def _init_lazy_attributes(self) -> None:
111120

112121
wp_version_args = ["--version", "--format", "json", "--no-banner"]
113122
try:
@@ -126,12 +135,17 @@ def _get_last_db_update(self) -> Optional[datetime]:
126135

127136
version_info = json.loads(process.stdout)
128137

129-
if not version_info.get("last_db_update", None):
130-
return None
131-
else:
132-
return datetime.strptime(
138+
if isinstance(version_info.get("last_db_update"), str):
139+
self._lazy_last_db_update = datetime.strptime(
133140
version_info["last_db_update"].split(".")[0], "%Y-%m-%dT%H:%M:%S"
134141
)
142+
else:
143+
self._lazy_last_db_update = None
144+
145+
try:
146+
self._lazy_wpscan_version = version_info['version']
147+
except KeyError:
148+
self._lazy_wpscan_version = None
135149

136150
def _update_wpscan(self) -> None:
137151
# Update wpscan database

0 commit comments

Comments
 (0)