Skip to content

Commit b4df818

Browse files
author
csavelief
committed
Add password structure in table
1 parent ab27837 commit b4df818

3 files changed

Lines changed: 45 additions & 17 deletions

File tree

app/Listeners/EndVulnsScanListener.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,34 @@ public static function sendEmailReport(YnhTrial $trial): void
4343
return;
4444
}
4545

46-
$query = "SELECT DISTINCT concat(login, '@', login_email_domain) AS email, concat(url_scheme, '://', url_subdomain, '.', url_domain) AS website FROM dumps_login_email_domain WHERE login_email_domain = '{$assets->first()->tld}' ORDER BY email ASC";
46+
$query = "SELECT DISTINCT concat(login, '@', login_email_domain) AS email, concat(url_scheme, '://', url_subdomain, '.', url_domain) AS website, password FROM dumps_login_email_domain WHERE login_email_domain = '{$assets->first()->tld}' ORDER BY email, website ASC";
4747

4848
Log::info($query);
4949

5050
$output = JosianneClient::executeQuery($query);
5151
$leaks = collect(explode("\n", $output))
5252
->filter(fn(string $line) => !empty($line) && $line !== 'ok')
5353
->map(function (string $line) {
54-
$line = trim($line);
5554
return [
56-
'email' => Str::before($line, "\t"),
57-
'website' => Str::after($line, "\t"),
55+
'email' => Str::trim(Str::before($line, "\t")),
56+
'website' => Str::trim(Str::between($line, "\t", "\t")),
57+
'password' => $this->maskPassword(Str::trim(Str::afterLast($line, "\t"))),
5858
];
5959
})
6060
->map(function (array $credentials) {
61-
if (preg_match("/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|(([^\s()<>]+|(([^\s()<>]+)))*))+(?:(([^\s()<>]+|(([^\s()<>]+)))*)|[^\s`!()[]{};:'\".,<>?«»“”‘’]))/", $credentials['website'])) {
61+
// if (preg_match("/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|(([^\s()<>]+|(([^\s()<>]+)))*))+(?:(([^\s()<>]+|(([^\s()<>]+)))*)|[^\s`!()[]{};:'\".,<>?«»“”‘’]))/", $credentials['website'])) {
62+
if (filter_var($credentials['website'], FILTER_VALIDATE_URL)) {
6263
return $credentials;
6364
}
6465
return [
6566
'email' => $credentials['email'],
6667
'website' => '',
68+
'password' => $credentials['password'],
6769
];
6870
})
69-
->unique(fn(array $credentials) => $credentials['email'] . $credentials['website'])
71+
->unique(fn(array $credentials) => $credentials['email'] . $credentials['website'] . $credentials['password'])
7072
->values();
71-
$msgLeaks = $leaks->isNotEmpty() ? "<li>J'ai trouvé <b>{$leaks->count()}</b> identifiants compromis appartenant au domaine {$assets->first()->tld}.</li>" : "";
73+
$msgLeaks = $leaks->isNotEmpty() ? "<li>J'ai trouvé <b>{$leaks->count()}</b> identifiants fuités ou compromis appartenant au domaine {$assets->first()->tld}.</li>" : "";
7274

7375
unset($output);
7476

@@ -120,10 +122,10 @@ public static function sendEmailReport(YnhTrial $trial): void
120122
})->join("");
121123

122124
if ($leaks->isNotEmpty()) {
123-
$website = $leaks->map(fn(array $leak) => "<li>L'identifiant <b>{$leak['email']}</b> donnant accès à <b>{$leak['website']}</b> a été compromis.</li>")->join("\n");
125+
$website = $leaks->map(fn(array $leak) => "<li>L'identifiant <b>{$leak['email']}</b> donnant accès à <b>{$leak['website']}</b> a été fuité ou compromis.</li>")->join("\n");
124126
$answer .= "
125-
<h3>Identifiants compromis</h3>
126-
<p>Cywise surveille également les fuites de données !<p>
127+
<h3>Identifiants fuités ou compromis</h3>
128+
<p>Cywise surveille également les fuites de données et compromissions !<p>
127129
<ul>
128130
{$website}
129131
</ul>
@@ -217,6 +219,14 @@ public static function sendEmail(string $from, string $to, string $subject, stri
217219
return [];
218220
}
219221

222+
private static function maskPassword(string $password): string
223+
{
224+
if (Str::length($password) <= 2) {
225+
return Str::repeat('*', Str::length($password));
226+
}
227+
return Str::substr($password, 0, 1) . Str::repeat('*', Str::length($password) - 2) . Str::substr($password, -1, 1);
228+
}
229+
220230
public function viaQueue(): string
221231
{
222232
return self::MEDIUM;

app/View/Components/Timeline.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,18 @@ private function leaks(User $user): array
330330
->unique()
331331
->join("','") . "'";
332332

333-
$query = "SELECT DISTINCT concat(login, '@', login_email_domain) AS email, concat(url_scheme, '://', url_subdomain, '.', url_domain) AS website FROM dumps_login_email_domain WHERE login_email_domain IN ({$tlds}) ORDER BY email ASC";
333+
$query = "SELECT DISTINCT concat(login, '@', login_email_domain) AS email, concat(url_scheme, '://', url_subdomain, '.', url_domain) AS website, password FROM dumps_login_email_domain WHERE login_email_domain IN ({$tlds}) ORDER BY email, website ASC";
334334

335335
Log::info($query);
336336

337337
$output = JosianneClient::executeQuery($query);
338338
$leaks = collect(explode("\n", $output))
339339
->filter(fn(string $line) => !empty($line) && $line !== 'ok')
340340
->map(function (string $line) {
341-
$line = trim($line);
342341
return [
343-
'email' => Str::before($line, "\t"),
344-
'website' => Str::after($line, "\t"),
342+
'email' => Str::trim(Str::before($line, "\t")),
343+
'website' => Str::trim(Str::between($line, "\t", "\t")),
344+
'password' => $this->maskPassword(Str::trim(Str::afterLast($line, "\t"))),
345345
];
346346
})
347347
->map(function (array $credentials) {
@@ -352,9 +352,10 @@ private function leaks(User $user): array
352352
return [
353353
'email' => $credentials['email'],
354354
'website' => '',
355+
'password' => $credentials['password'],
355356
];
356357
})
357-
->unique(fn(array $credentials) => $credentials['email'] . $credentials['website']);
358+
->unique(fn(array $credentials) => $credentials['email'] . $credentials['website'] . $credentials['password']);
358359

359360
if (count($leaks) > 0) {
360361

@@ -365,7 +366,8 @@ private function leaks(User $user): array
365366
$leaks = $leaks->filter(function (array $leak) use ($leaksPrev) {
366367
return !$leaksPrev->contains(function (object $leakPrev) use ($leak) {
367368
return $leakPrev->email === $leak['email'] &&
368-
$leakPrev->website === $leak['website'];
369+
$leakPrev->website === $leak['website'] &&
370+
$leakPrev->password === $leak['password'];
369371
});
370372
});
371373

@@ -537,4 +539,12 @@ private function events(User $user): array
537539
})
538540
->toArray();
539541
}
542+
543+
private function maskPassword(string $password): string
544+
{
545+
if (Str::length($password) <= 2) {
546+
return Str::repeat('*', Str::length($password));
547+
}
548+
return Str::substr($password, 0, 1) . Str::repeat('*', Str::length($password) - 2) . Str::substr($password, -1, 1);
549+
}
540550
}

resources/views/cywise/_timeline-item-leak.blade.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,28 @@ class="icon icon-tabler icons-tabler-outline icon-tabler-password-user">
6666
</span>
6767
<div class="timeline-item-wrapper">
6868
<div class="timeline-item-description">
69-
<span>Nous avons trouvé <b>{{ count(json_decode($leak->attributes()['credentials'])) }} identifiants compromis</b>. Si aucune action n'a encore été entreprise, demandez aux utilisateurs concernés de modifier leur mot de passe.</span>
69+
<span>Nous avons trouvé <b>{{ count(json_decode($leak->attributes()['credentials'])) }} identifiants fuités ou compromis</b>. Si aucune action n'a encore été entreprise, demandez aux utilisateurs concernés de modifier leur mot de passe.</span>
7070
</div>
7171
<table>
7272
<thead>
7373
<tr>
7474
<th>{{ __('Email') }}</th>
7575
<th>{{ __('Website') }}</th>
76+
<th>{{ __('Password') }}</th>
77+
<th></th>
7678
</tr>
7779
</thead>
7880
<tbody>
7981
@foreach(json_decode($leak->attributes()['credentials']) as $l)
8082
<tr>
8183
<td>{{ $l->email }}</td>
8284
<td>{{ empty($l->website) ? '-' : $l->website }}</td>
85+
<td>{{ empty($l->password) ? '-' : $l->password }}</td>
86+
<td>
87+
<span class="lozenge new">
88+
{{ empty($l->website) ? __('fuite de données') : __('possible compromission') }}
89+
</span>
90+
</td>
8391
</tr>
8492
@endforeach
8593
</tbody>

0 commit comments

Comments
 (0)