src/Controller/ClientController.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\DarkOwl;
  4. use App\Entity\Domain;
  5. use App\Entity\ExposedIp;
  6. use App\Entity\ExposedSubDomain;
  7. use App\Entity\LeakedPassword;
  8. use App\Entity\Organisation;
  9. use App\Entity\User;
  10. use App\Entity\Vulnerability;
  11. use App\Entity\VulnerabilityLevel;
  12. use App\Manager\LeakedPasswordManager;
  13. use App\Repository\CronLogRepository;
  14. use App\Repository\DarkOwlRepository;
  15. use App\Repository\DomainRepository;
  16. use App\Repository\ExposedIpRepository;
  17. use App\Repository\ExposedSubDomainRepository;
  18. use App\Repository\LeakedPasswordRepository;
  19. use App\Repository\VulnerabilityRepository;
  20. use App\Service\Misc;
  21. use App\Service\ScoreService;
  22. use App\Service\Stats;
  23. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  24. use Symfony\Component\HttpFoundation\JsonResponse;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  29. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  30. use Symfony\Component\HttpFoundation\HeaderUtils;
  31. class ClientController extends AbstractController
  32. {
  33.     /**
  34.      * @var Stats $stats
  35.      */
  36.     private $stats;
  37.     /**
  38.      * @var Misc $misc
  39.      */
  40.     private $misc;
  41.     public function __construct(Stats $statsMisc $misc)
  42.     {
  43.         $this->stats $stats;
  44.         $this->misc $misc;
  45.     }
  46.     /**
  47.      * @Route("/", name="home")
  48.      */
  49.     public function index(DomainRepository $domainRepository)
  50.     {
  51.         if ($this->getUser()->isAdmin()) {
  52.             return $this->redirectToRoute('admin_dashboard');
  53.         }
  54.         /**
  55.          * @var User $user
  56.          */
  57.         $user $this->getUser();
  58.         $organisation $this->misc->getUserOrganisation($user);
  59.         $leakedPassword $this->stats->getLeakedPasswordStats($organisation);
  60.         $exposedSubDomain $this->stats->getExposedDomainStats($organisation);
  61.         $exposedIp $this->stats->getExposedIpStats($organisation);
  62.         $vulnerability $this->stats->getVulneranilityStats($organisation);
  63.         $score null;
  64.         /**
  65.          * @var Domain $domain
  66.          */
  67.         foreach ($domainRepository->findDomainsByOrga($organisation) as $domain) {
  68.             $score $domain->getLastScore();
  69.         }
  70.         $data = [];
  71.         if ($score) {
  72.             $value $score->getScore();
  73.             if ($value == 0) {
  74.                 $data = [
  75.                     "class" => "none",
  76.                     "label" => "Info",
  77.                 ];
  78.             } elseif ($value >= 0.1 && $value 4) {
  79.                 $data = [
  80.                     "class" => "low",
  81.                     "label" => "Low",
  82.                 ];
  83.             } elseif ($value >= && $value 7) {
  84.                 $data = [
  85.                     "class" => "medium",
  86.                     "label" => "Medium",
  87.                 ];
  88.             } elseif ($value >= && $value 9) {
  89.                 $data = [
  90.                     "class" => "high",
  91.                     "label" => "High",
  92.                 ];
  93.             } elseif ($value >= && $value <= 10) {
  94.                 $data = [
  95.                     "class" => "critical",
  96.                     "label" => "Critical",
  97.                 ];
  98.             }
  99.         }
  100.         return $this->render('client/index.html.twig', [
  101.             'leakedPassword' => $leakedPassword,
  102.             'exposedDomain' => $exposedSubDomain,
  103.             'exposedIp' => $exposedIp,
  104.             'vulnerability' => $vulnerability,
  105.             'score' => $score,
  106.             'data' => $data,
  107.             'organisation' => $organisation,
  108.             'sub' => $this->misc->getActifSubsription($organisation),
  109.         ]);
  110.     }
  111.     /**
  112.      * @IsGranted("leaked-passwords")
  113.      * @Route("/leaked-passwords", name="leakedpassowrds")
  114.      */
  115.     public function leakedPassword(
  116.         Request $request,
  117.         LeakedPasswordRepository $leakedPasswordRepository,
  118.         ScoreService $service
  119.     )
  120.     {
  121.         /**
  122.          * @var User $user
  123.          */
  124.         $user $this->getUser();
  125.         $organisation $this->misc->getUserOrganisation($user);
  126.         $today $request->query->get('today'false) === "1";
  127.         $leakedPasswords $leakedPasswordRepository->findLeakedPasswordsByDate(
  128.             $organisation,
  129.             $today date('Y-m-d') : null
  130.         );
  131.         return $this->render('client/leakedpasswords.html.twig', [
  132.             'leakedpasswords' => $leakedPasswords,
  133.         ]);
  134.     }
  135.     /**
  136.      * @IsGranted("leaked-passwords")
  137.      * @Route("/leaked-password/{id}/notify", name="leakedpassowrd_notify")
  138.      */
  139.     public function notifyLeakedPassword(
  140.         LeakedPassword $leakedPassword,
  141.         LeakedPasswordManager $leakedPasswordManager,
  142.         Request $request
  143.     ): Response {
  144.         $notify filter_var($request->query->get('notify'false), FILTER_VALIDATE_BOOLEAN);
  145.         $leakedPasswordManager->notifyLeakedPassword(
  146.             $leakedPassword,
  147.             $this->getUser(),
  148.             $notify
  149.         );
  150.         return new JsonResponse(['response' => 'ok']);
  151.     }
  152.     /**
  153.      * @IsGranted("exposed-sub-domains")
  154.      * @Route("/exposed-domains/{id}/normal", name="normal_exposed_domain")
  155.      */
  156.     public function normalExposedDomain(
  157.         ExposedSubDomain $exposedSubDomain,
  158.         Request $request
  159.     ): Response {
  160.         $user $this->getUser();
  161.         $status filter_var($request->query->get('status'false), FILTER_VALIDATE_BOOLEAN);
  162.         if ($exposedSubDomain->getDomain()->getOrganisation()->getId() === $this->misc->getUserOrganisation($user)->getId()) {
  163.             $exposedSubDomain->setIsNormal($status);
  164.             $this->getDoctrine()->getManager()->flush();
  165.         }
  166.         return new JsonResponse(['response' => 'ok']);
  167.     }
  168.     /**
  169.      * @IsGranted("exposed-sub-domains")
  170.      * @Route("/exposed-subdomains", name="exposedsubdomains")
  171.      */
  172.     public function exposedSubDomains(Request $requestExposedSubDomainRepository $exposedSubDomainRepository)
  173.     {
  174.         /**
  175.          * @var User $user
  176.          */
  177.         $user $this->getUser();
  178.         $organisation $this->misc->getUserOrganisation($user) ;
  179.         return $this->render('client/exposedsubdomains.html.twig', [
  180.             'subdomains' => $exposedSubDomainRepository->findExposedSubDomainsByOrganisationAndDate($organisation),
  181.             'today' =>  $request->query->get('today'false) === "1"
  182.         ]);
  183.     }
  184.     /**
  185.      * @IsGranted("exposed-ips-and-ports")
  186.      * @Route("/exposed-ips-ports/{id}/normal", name="normal_exposed_ip")
  187.      */
  188.     public function normalExposedIp(
  189.         ExposedIp $exposedIp,
  190.         Request $request
  191.     ): Response {
  192.         $user $this->getUser();
  193.         $status filter_var($request->query->get('normal'false), FILTER_VALIDATE_BOOLEAN);
  194.         if ($exposedIp->getOrganisation()->getId() === $this->misc->getUserOrganisation($user)->getId()) {
  195.             $exposedIp->setIsNormal(!$status);
  196.             $this->getDoctrine()->getManager()->flush();
  197.         }
  198.         return new JsonResponse([
  199.             'response' => 'ok',
  200.             'class' => !$status 'normal' 'abnormal',
  201.             'html' => !$status 'Normal' 'Abnormal',
  202.         ]);
  203.     }
  204.     /**
  205.      * @IsGranted("exposed-ips-and-ports")
  206.      * @Route("/exposed-ips-ports", name="exposedipsports")
  207.      */
  208.     public function exposedIpsPorts(ExposedIpRepository $exposedIpRepository)
  209.     {
  210.         /**
  211.          * @var User $user
  212.          */
  213.         $user $this->getUser();
  214.         /**
  215.          * @var Organisation $organisation
  216.          */
  217.         $organisation  $this->misc->getUserOrganisation($user);
  218.         return $this->render(
  219.             'client/exposedipsports.html.twig',
  220.             [
  221.                 "ips" => $exposedIpRepository->findExposedIpsByOrgaAndDate($organisation)
  222.             ]
  223.         );
  224.     }
  225.     /**
  226.      * @IsGranted("potential-vulnerabilities")
  227.      * @Route("/potential-vulnerabilities", name="potentialvulnerabilities")
  228.      */
  229.     public function potentialVulnerabilities(
  230.         Request $request,
  231.         CronLogRepository $cronLogRepository,
  232.         DomainRepository $domainRepository
  233.     ) {
  234.         $today $request->query->get('today'false) === "1";
  235.         /**
  236.          * @var User $user
  237.          */
  238.         $user $this->getUser();
  239.         $organisation $this->misc->getUserOrganisation($user);
  240.         $lastExec $cronLogRepository
  241.             ->findOneBy(
  242.                 ['organisation' => $organisation'commandName' => 'app:processing-organization'],
  243.                 ['id' => 'DESC']
  244.             );
  245.         $domains = [];
  246.         /**
  247.          * @var Domain $domain
  248.          */
  249.         foreach ($domainRepository->findDomainsByOrga($organisation) as $domain) {
  250.             if (!isset($domains[$domain->getUrl()])) {
  251.                 $domains[$domain->getUrl()] = [];
  252.             }
  253.             /**
  254.              * @var Vulnerability $vul
  255.              */
  256.             foreach ($domain->getVulnerabilities() as $vul) {
  257.                 if ($today && $vul->getCreatedAt()->format('Y-m-d') != date('Y-m-d')) {
  258.                     continue;
  259.                 }
  260.                 $key $this->getUrl($vul->getMetadata()) ;
  261.                 if (!isset($domains[$key][$vul->getLevel()->getSlug()])) {
  262.                     $domains[$key][$vul->getLevel()->getSlug()] = [];
  263.                 }
  264.                 $domains[$key][$vul->getLevel()->getSlug()] = $vul->getLevel();
  265.             }
  266.         }
  267.         return $this->render('client/potentialvulnerabilities.html.twig', [
  268.             'domains' => $domains,
  269.             'today' => $today,
  270.             'lastExec' => $lastExec,
  271.         ]);
  272.     }
  273.     /**
  274.      * @IsGranted("potential-vulnerabilities")
  275.      * @Route("/get-vulnerabilities", name="getvulnerabilities")
  276.      */
  277.     public function getVulnerabilities(
  278.         Request $request,
  279.         VulnerabilityRepository $vulnerabilityRepository
  280.     ) {
  281.         /**
  282.          * @var User $user
  283.          */
  284.         $user $this->getUser();
  285.         $domain_url $request->query->get('domain');
  286.         $level_id $request->query->get('level'\false);
  287.         $today $request->query->get('today'\false);
  288.         $vuls $vulnerabilityRepository->findVulnerabilitiesByDomainAndLevel($domain_url$level_id$today);
  289.         if (!empty($vuls)) {
  290.             $v $vuls[0];
  291.             if ($v->getDomain()->getOrganisation()->getId() !== $this->misc->getUserOrganisation($user)->getId()) {
  292.                 $vuls = [];
  293.             }
  294.         }
  295.         $levels = [];
  296.         foreach ($vuls as $vul) {
  297.             $levels[] = $vul->getLevel()->getSlug();
  298.         }
  299.         return $this->render('client/tablevulnerabilities.html.twig', [
  300.             'vuls' => $vuls,
  301.             'levels' => \array_unique($levels),
  302.         ]);
  303.     }
  304.     /**
  305.      * @Route("/notifications", name="notifications")
  306.      */
  307.     public function notifications()
  308.     {
  309.         /**
  310.          * @var User $user
  311.          */
  312.         $user $this->getUser();
  313.         $em $this->getDoctrine()->getManager();
  314.         $leakedPassword $em->getRepository(LeakedPassword::class)->findLeakedPasswordsByDate(
  315.             $this->misc->getUserOrganisation($user),
  316.             date('Y-m-d'),
  317.             '%Y-%m-%d'
  318.         );
  319.         $exposedSubDomain $em->getRepository(ExposedSubDomain::class)->findExposedSubDomainsByOrganisationAndDate(
  320.             $this->misc->getUserOrganisation($user),
  321.             date('Y-m-d'),
  322.             '%Y-%m-%d'
  323.         );
  324.         $vulnerability $em->getRepository(Vulnerability::class)->findVulnerabilitiesByOrganisationAndDate(
  325.             $this->misc->getUserOrganisation($user),
  326.             date('Y-m-d'),
  327.             '%Y-%m-%d'
  328.         );
  329.         $count 0;
  330.         if (count($leakedPassword)>0) {
  331.             $count++;
  332.         }
  333.         if (count($exposedSubDomain)>0) {
  334.             $count++;
  335.         }
  336.         if (count($vulnerability)>0) {
  337.             $count++;
  338.         }
  339.         return $this->render('partials/customer/notifications.html.twig', [
  340.             'count' => $count,
  341.             'leakedPassword' => count($leakedPassword),
  342.             'exposedSubDomain' => count($exposedSubDomain),
  343.             'vulnerability' => count($vulnerability),
  344.         ]);
  345.     }
  346.     /**
  347.      * @IsGranted("dark-web-exposure")
  348.      * @Route("/dark-web-exposure", name="darkwebexposure")
  349.      */
  350.     public function darkwebexposure(Request $requestDarkOwlRepository $darkOwlRepository)
  351.     {
  352.         /**
  353.         * @var User $user
  354.         */
  355.         $user $this->getUser();
  356.         $datas $darkOwlRepository->findByOrganisation($this->misc->getUserOrganisation($user));
  357.         return $this->render('client/darkwebexposure.html.twig', [
  358.             'darkOwls' => $datas
  359.         ]);
  360.     }
  361.     /**
  362.      * @IsGranted("dark-web-exposure")
  363.      * @Route("/dark-web-exposure/{documentID}", name="darkwebexposure-details")
  364.      */
  365.     public function darkwebexposureDetails(Request $requestDarkOwl $darkOwl)
  366.     {
  367.         return $this->render('client/darkwebexposure-details.html.twig', [
  368.             'darkowl' => $darkOwl
  369.         ]);
  370.     }
  371.     /**
  372.      * @IsGranted("dark-web-exposure")
  373.      * @Route("/dark-web-exposure/{documentID}/download", name="darkwebexposure-download")
  374.      */
  375.     public function downloadDarkwebexposureDetails(Request $requestDarkOwl $darkOwl)
  376.     {
  377.         $body \str_replace('\n'"\n"$darkOwl->getBody());
  378.         $filename 'cypherleak-'.$darkOwl->getDocumentID().'.txt';
  379.         $filepath sys_get_temp_dir().\DIRECTORY_SEPARATOR.$filename;
  380.         $file \fopen($filepath'w');
  381.         \fwrite($file$body);
  382.         \fclose($file);
  383.         $response = new BinaryFileResponse($filepath);
  384.         $disposition HeaderUtils::makeDisposition(
  385.             HeaderUtils::DISPOSITION_ATTACHMENT,
  386.             $filename
  387.         );
  388.         $response->headers->set('Content-Disposition'$disposition);
  389.         return $response;
  390.     }
  391.     
  392.     private function getUrl($url)
  393.     {
  394.         $parts \explode('/'$url);
  395.         return count($parts)>= $parts[0].'//'.$parts[2] : $url;
  396.     }
  397. }