lonkero 3.7.0

Web scanner built for actual pentests. Fast, modular, Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
// Copyright (c) 2026 Bountyy Oy. All rights reserved.
// This software is proprietary and confidential.

use crate::http_client::HttpClient;
use crate::types::{Confidence, ScanConfig, Severity, Vulnerability};
use anyhow::Result;
use regex::Regex;
use std::collections::HashMap;
use std::sync::Arc;
use tracing::{debug, info};

pub struct JoomlaScanner {
    http_client: Arc<HttpClient>,
    known_vulnerabilities: HashMap<String, Vec<JoomlaVulnerability>>,
}

#[derive(Clone)]
struct JoomlaVulnerability {
    name: String,
    #[allow(dead_code)]
    vulnerable_version: String,
    #[allow(dead_code)]
    cve: Option<String>,
    severity: Severity,
    description: String,
}

#[derive(Debug, Clone)]
struct JoomlaVersion {
    major: u32,
    minor: u32,
    patch: u32,
}

impl JoomlaScanner {
    pub fn new(http_client: Arc<HttpClient>) -> Self {
        Self {
            http_client,
            known_vulnerabilities: Self::build_vulnerability_db(),
        }
    }

    fn build_vulnerability_db() -> HashMap<String, Vec<JoomlaVulnerability>> {
        let mut db = HashMap::new();
        let vulnerabilities = vec![
            JoomlaVulnerability {
                name: "com_jce".to_string(),
                vulnerable_version: "2.6.38".to_string(),
                cve: Some("CVE-2020-35936".to_string()),
                severity: Severity::Critical,
                description: "JCE Editor file upload bypass RCE".to_string(),
            },
            JoomlaVulnerability {
                name: "com_fabrik".to_string(),
                vulnerable_version: "3.10".to_string(),
                cve: None,
                severity: Severity::Critical,
                description: "Fabrik file upload arbitrary file write".to_string(),
            },
        ];
        for vuln in vulnerabilities {
            db.entry(vuln.name.clone())
                .or_insert_with(Vec::new)
                .push(vuln);
        }
        db
    }

    pub async fn scan(
        &self,
        target: &str,
        _config: &ScanConfig,
    ) -> Result<(Vec<Vulnerability>, usize)> {
        let mut vulnerabilities = Vec::new();
        let mut tests = 0;

        let (is_joomla, version) = self.detect_joomla(target).await?;
        tests += 1;

        if !is_joomla {
            debug!("Target does not appear to be a Joomla installation");
            return Ok((vulnerabilities, tests));
        }

        info!("Detected Joomla installation at {}", target);
        if let Some(ref v) = version {
            info!("Joomla version: {}.{}.{}", v.major, v.minor, v.patch);
        }

        let (version_vulns, t) = self.check_version_vulnerabilities(target, &version).await?;
        vulnerabilities.extend(version_vulns);
        tests += t;

        let (admin_vulns, t) = self.check_admin_exposure(target).await?;
        vulnerabilities.extend(admin_vulns);
        tests += t;

        let (config_vulns, t) = self.check_config_exposure(target).await?;
        vulnerabilities.extend(config_vulns);
        tests += t;

        let (api_vulns, t) = self.check_api_exposure(target).await?;
        vulnerabilities.extend(api_vulns);
        tests += t;

        let (ext_vulns, t) = self.check_extension_vulnerabilities(target).await?;
        vulnerabilities.extend(ext_vulns);
        tests += t;

        let (install_vulns, t) = self.check_installation_files(target).await?;
        vulnerabilities.extend(install_vulns);
        tests += t;

        Ok((vulnerabilities, tests))
    }

    async fn detect_joomla(&self, target: &str) -> Result<(bool, Option<JoomlaVersion>)> {
        let mut version: Option<JoomlaVersion> = None;

        let detection_urls = vec![
            format!("{}/administrator/manifests/files/joomla.xml", target),
            format!("{}/language/en-GB/en-GB.xml", target),
        ];

        for url in &detection_urls {
            if let Ok(response) = self.http_client.get(url).await {
                if response.status_code == 200 {
                    if url.ends_with(".xml") {
                        if let Some(v) = self.extract_version_from_xml(&response.body) {
                            version = Some(v);
                        }
                    }
                    return Ok((true, version));
                }
            }
        }

        // Check main page for Joomla generator meta tag - this is the most reliable indicator.
        // Previously matched `body.contains("joomla")` alone which matches any page
        // that mentions Joomla in text (blog posts, docs, comparisons).
        // Now require the Joomla generator meta tag or Joomla-specific HTML patterns.
        if let Ok(response) = self.http_client.get(target).await {
            if response.status_code == 200 {
                let body_lower = response.body.to_lowercase();
                let has_joomla_meta = body_lower.contains("content=\"joomla")
                    || body_lower.contains("generator\" content=\"joomla");
                let has_joomla_structure = body_lower.contains("/media/jui/")
                    || body_lower.contains("/media/system/")
                        && body_lower.contains("joomla");

                if has_joomla_meta || has_joomla_structure {
                    let version_regex = Regex::new(
                        r#"generator"[^>]*content="Joomla!\s*(\d+)\.(\d+)(?:\.(\d+))?"#,
                    )
                    .ok();
                    if let Some(re) = version_regex {
                        if let Some(caps) = re.captures(&response.body) {
                            let major = caps
                                .get(1)
                                .and_then(|m| m.as_str().parse().ok())
                                .unwrap_or(0);
                            let minor = caps
                                .get(2)
                                .and_then(|m| m.as_str().parse().ok())
                                .unwrap_or(0);
                            let patch = caps
                                .get(3)
                                .and_then(|m| m.as_str().parse().ok())
                                .unwrap_or(0);
                            version = Some(JoomlaVersion {
                                major,
                                minor,
                                patch,
                            });
                        }
                    }
                    return Ok((true, version));
                }
            }
        }

        Ok((false, None))
    }

    fn extract_version_from_xml(&self, content: &str) -> Option<JoomlaVersion> {
        let version_regex = Regex::new(r"<version>(\d+)\.(\d+)(?:\.(\d+))?</version>").ok()?;
        if let Some(caps) = version_regex.captures(content) {
            let major = caps
                .get(1)
                .and_then(|m| m.as_str().parse().ok())
                .unwrap_or(0);
            let minor = caps
                .get(2)
                .and_then(|m| m.as_str().parse().ok())
                .unwrap_or(0);
            let patch = caps
                .get(3)
                .and_then(|m| m.as_str().parse().ok())
                .unwrap_or(0);
            return Some(JoomlaVersion {
                major,
                minor,
                patch,
            });
        }
        None
    }

    async fn check_version_vulnerabilities(
        &self,
        target: &str,
        version: &Option<JoomlaVersion>,
    ) -> Result<(Vec<Vulnerability>, usize)> {
        let mut vulnerabilities = Vec::new();
        let tests = 1;

        if let Some(v) = version {
            // Check CVE-2023-23752 (Joomla 4.0.0 - 4.2.7)
            if v.major == 4 && (v.minor < 2 || (v.minor == 2 && v.patch <= 7)) {
                let api_url = format!("{}/api/index.php/v1/config/application?public=true", target);
                if let Ok(response) = self.http_client.get(&api_url).await {
                    if response.status_code == 200 && response.body.contains("dbtype") {
                        vulnerabilities.push(Vulnerability {
                            id: generate_vuln_id(),
                            vuln_type: "Information Disclosure".to_string(),
                            severity: Severity::Critical,
                            confidence: Confidence::High,
                            category: "CMS Security".to_string(),
                            url: api_url,
                            parameter: None,
                            payload: "CVE-2023-23752".to_string(),
                            description:
                                "CVE-2023-23752: Joomla REST API exposes database credentials"
                                    .to_string(),
                            evidence: Some(
                                "Database configuration accessible without authentication"
                                    .to_string(),
                            ),
                            cwe: "CWE-284".to_string(),
                            cvss: 7.5,
                            verified: true,
                            false_positive: false,
                            remediation: "Upgrade to Joomla 4.2.8 or later".to_string(),
                            discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                        });
                    }
                }
            }

            // Check CVE-2017-8917 (Joomla 3.7.0)
            if v.major == 3 && v.minor == 7 && v.patch == 0 {
                vulnerabilities.push(Vulnerability {
                    id: generate_vuln_id(),
                    vuln_type: "SQL Injection".to_string(),
                    severity: Severity::Critical,
                    confidence: Confidence::High,
                    category: "CMS Security".to_string(),
                    url: target.to_string(),
                    parameter: Some("list[fullordering]".to_string()),
                    payload: "CVE-2017-8917".to_string(),
                    description: "CVE-2017-8917: Joomla 3.7.0 com_fields SQL injection".to_string(),
                    evidence: Some(format!(
                        "Detected vulnerable version {}.{}.{}",
                        v.major, v.minor, v.patch
                    )),
                    cwe: "CWE-89".to_string(),
                    cvss: 9.8,
                    verified: false,
                    false_positive: false,
                    remediation: "Upgrade to Joomla 3.7.1 or later".to_string(),
                    discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                });
            }
        }

        Ok((vulnerabilities, tests))
    }

    async fn check_admin_exposure(&self, target: &str) -> Result<(Vec<Vulnerability>, usize)> {
        let mut vulnerabilities = Vec::new();
        let tests = 1;

        let url = format!("{}/administrator/", target);
        if let Ok(response) = self.http_client.get(&url).await {
            if response.status_code == 200 && response.body.contains("mod-login") {
                vulnerabilities.push(Vulnerability {
                    id: generate_vuln_id(),
                    vuln_type: "Information Disclosure".to_string(),
                    severity: Severity::Low,
                    confidence: Confidence::High,
                    category: "CMS Security".to_string(),
                    url: url.clone(),
                    parameter: None,
                    payload: String::new(),
                    description: "Joomla administrator panel is publicly accessible".to_string(),
                    evidence: Some("Admin login form detected".to_string()),
                    cwe: "CWE-200".to_string(),
                    cvss: 3.7,
                    verified: true,
                    false_positive: false,
                    remediation:
                        "Restrict access to administrator panel using .htaccess or firewall"
                            .to_string(),
                    discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                });
            }
        }

        Ok((vulnerabilities, tests))
    }

    async fn check_config_exposure(&self, target: &str) -> Result<(Vec<Vulnerability>, usize)> {
        let mut vulnerabilities = Vec::new();
        let mut tests = 0;

        let config_paths = vec![
            "/configuration.php~",
            "/configuration.php.bak",
            "/configuration.php.old",
        ];

        for path in config_paths {
            let url = format!("{}{}", target, path);
            tests += 1;

            if let Ok(response) = self.http_client.get(&url).await {
                if response.status_code == 200
                    && (response.body.contains("$host")
                        || response.body.contains("$db")
                        || response.body.contains("$password"))
                {
                    vulnerabilities.push(Vulnerability {
                        id: generate_vuln_id(),
                        vuln_type: "Information Disclosure".to_string(),
                        severity: Severity::Critical,
                        confidence: Confidence::High,
                        category: "CMS Security".to_string(),
                        url: url.clone(),
                        parameter: None,
                        payload: path.to_string(),
                        description: format!("Joomla configuration backup file exposed: {}", path),
                        evidence: Some(
                            "Configuration file contains database credentials".to_string(),
                        ),
                        cwe: "CWE-538".to_string(),
                        cvss: 9.1,
                        verified: true,
                        false_positive: false,
                        remediation:
                            "Remove backup configuration files from web-accessible directories"
                                .to_string(),
                        discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                    });
                }
            }
        }

        Ok((vulnerabilities, tests))
    }

    async fn check_api_exposure(&self, target: &str) -> Result<(Vec<Vulnerability>, usize)> {
        let mut vulnerabilities = Vec::new();
        let mut tests = 0;

        let api_endpoints = vec![
            "/api/index.php/v1/config/application",
            "/api/index.php/v1/users",
        ];

        for endpoint in api_endpoints {
            let url = format!("{}{}", target, endpoint);
            tests += 1;

            if let Ok(response) = self.http_client.get(&url).await {
                if response.status_code == 200 {
                    if endpoint.contains("config") && response.body.contains("dbtype") {
                        vulnerabilities.push(Vulnerability {
                            id: generate_vuln_id(),
                            vuln_type: "Information Disclosure".to_string(),
                            severity: Severity::Critical,
                            confidence: Confidence::High,
                            category: "CMS Security".to_string(),
                            url: url.clone(),
                            parameter: None,
                            payload: endpoint.to_string(),
                            description: "Joomla REST API exposes application configuration"
                                .to_string(),
                            evidence: Some(
                                "Database configuration exposed without authentication".to_string(),
                            ),
                            cwe: "CWE-284".to_string(),
                            cvss: 7.5,
                            verified: true,
                            false_positive: false,
                            remediation:
                                "Restrict API access and upgrade to patched Joomla version"
                                    .to_string(),
                            discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                        });
                    } else if endpoint.contains("users") && response.body.contains("email") {
                        vulnerabilities.push(Vulnerability {
                            id: generate_vuln_id(),
                            vuln_type: "User Enumeration".to_string(),
                            severity: Severity::Medium,
                            confidence: Confidence::High,
                            category: "CMS Security".to_string(),
                            url: url.clone(),
                            parameter: None,
                            payload: endpoint.to_string(),
                            description: "Joomla REST API exposes user information".to_string(),
                            evidence: Some("User details including emails accessible".to_string()),
                            cwe: "CWE-200".to_string(),
                            cvss: 5.3,
                            verified: true,
                            false_positive: false,
                            remediation: "Restrict API access with proper authentication"
                                .to_string(),
                            discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                        });
                    }
                }
            }
        }

        Ok((vulnerabilities, tests))
    }

    async fn check_extension_vulnerabilities(
        &self,
        target: &str,
    ) -> Result<(Vec<Vulnerability>, usize)> {
        let mut vulnerabilities = Vec::new();
        let mut tests = 0;

        let extensions = vec![
            ("com_jce", "/administrator/components/com_jce/"),
            ("com_fabrik", "/components/com_fabrik/"),
        ];

        for (ext_name, ext_path) in extensions {
            let url = format!("{}{}", target, ext_path);
            tests += 1;

            if let Ok(response) = self.http_client.get(&url).await {
                // Only report if extension is ACCESSIBLE (200), not just blocked (403).
                // A 403 means the server is blocking access, which is PROTECTION, not vulnerability.
                // Reporting on 403 creates false positives for properly secured extensions.
                if response.status_code == 200 {
                    if let Some(vulns) = self.known_vulnerabilities.get(ext_name) {
                        for vuln in vulns {
                            vulnerabilities.push(Vulnerability {
                                id: generate_vuln_id(),
                                vuln_type: format!("{} Vulnerability", vuln.description),
                                severity: vuln.severity.clone(),
                                confidence: Confidence::Medium,
                                category: "CMS Security".to_string(),
                                url: url.clone(),
                                parameter: None,
                                payload: ext_name.to_string(),
                                description: format!(
                                    "Potentially vulnerable Joomla extension: {} - {}",
                                    ext_name, vuln.description
                                ),
                                evidence: Some(format!("Extension {} detected", ext_name)),
                                cwe: "CWE-1035".to_string(),
                                cvss: 7.5,
                                verified: false,
                                false_positive: false,
                                remediation: format!("Update {} to the latest version", ext_name),
                                discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                            });
                        }
                    }
                }
            }
        }

        Ok((vulnerabilities, tests))
    }

    async fn check_installation_files(&self, target: &str) -> Result<(Vec<Vulnerability>, usize)> {
        let mut vulnerabilities = Vec::new();
        let tests = 1;

        let url = format!("{}/installation/", target);
        if let Ok(response) = self.http_client.get(&url).await {
            if response.status_code == 200 && response.body.contains("install") {
                vulnerabilities.push(Vulnerability {
                    id: generate_vuln_id(),
                    vuln_type: "Security Misconfiguration".to_string(),
                    severity: Severity::Critical,
                    confidence: Confidence::High,
                    category: "CMS Security".to_string(),
                    url: url.clone(),
                    parameter: None,
                    payload: "/installation/".to_string(),
                    description:
                        "Joomla installation directory accessible - site may be reinstallable"
                            .to_string(),
                    evidence: Some("Installation wizard accessible".to_string()),
                    cwe: "CWE-284".to_string(),
                    cvss: 9.8,
                    verified: true,
                    false_positive: false,
                    remediation: "Remove the installation directory after setup".to_string(),
                    discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                });
            }
        }

        Ok((vulnerabilities, tests))
    }
}

fn generate_vuln_id() -> String {
    use std::time::{SystemTime, UNIX_EPOCH};
    let timestamp = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .unwrap_or_default()
        .as_nanos();
    format!("JOOMLA-{:x}", timestamp)
}