rss logo

Générer du trafic web aléatoire depuis Internet Explorer avec PowerShell

J'ai eu besoin de simuler du trafic web sur de nombreuses stations Windows. Ne pouvant me démultiplier j'ai écris un script PowerShell qui ouvre de façon aléatoire des sites web avec Internet Explorer ou télécharge des fichiers depuis internet.

Code

###########################
# author : shebangthedolphins.net
# version : 1.0
# date : 2019.02
# role : open internet explorer to generate random web trafic
# other :
# - Tested on a Windows 7 host
# updates :
#       - 1.0 : first version

#Variables definition
$url1 = "https://usconstitution.net/"
$url2 = "https://qwant.com"
$url3 = "https://ddg.gg"
$url4 = "http://dell.com"
$url5 = "http://msn.com"
$url6 = "http://www.yahoo.fr"
$url7 = "https://fr.news.yahoo.com/"
$url8 = "https://news.google.com/?tab=wn&hl=fr&gl=FR&ceid=FR:fr"

function Random-Number {
    Get-Random -Minimum $args[0] -Maximum $args[1];
}

function Ready {
    $count = 0
    while($ie.ReadyState -ne 4)  {
        Start-Sleep -m 200;
        Write-Host "I'm ready : $count" + $ie.ReadyState
        $count++;
        If ($count -eq 100) {
            Get-Process | ? { $_.ProcessName -eq 'iexplore' } | Stop-Process
            Get-Process | ? { $_.ProcessName -eq 'werfault' } | Stop-Process
            [System.GC]::Collect() #garbage collector source : https://dmitrysotnikov.wordpress.com/2012/02/24/freeing-up-memory-in-powershell-using-garbage-collector/
            return $false
            break
        }
    } return $true
}

function IE {
    $navOpenInBackgroundTab = 0x1000; #Open the resource or file in a new background tab; the currently active window and/or tab remains open on top.
    $ie = New-Object -COMObject internetexplorer.application;
    $ie.visible = $true;
    return $ie
}

$ie = IE

While($true)
{
    $result = Random-Number 2 10
    Write-Host "sleep pendant $result"
    #Start-Sleep $result

    $result = Random-Number 0 8

    If ($result -ne "0") {
        #Internet Explorer
        $SleepTime = Random-Number 2 5
        Write-Host "Internet Explorer, nous allons vers l'url : $result"
        
    switch ($result) {
       "1"  {
            $ie.navigate($url1); #main tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100};
            if(!(Ready $ie)) { $ie = IE } 
            break
            }
       "2"  {
            $ie.navigate($url2); #main tab link
            #$ie.navigate($url5,$navOpenInBackgroundTab); #secondary tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100}; 
            if(!(Ready $ie)) { $ie = IE }
            break
            }
       "3"   {
            $ie.navigate($url3); #main tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100};
            if(!(Ready $ie)) { $ie = IE }
            break
             }
       "4" {
            $ie.navigate($url4); #main tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100};
            if(!(Ready $ie)) { $ie = IE }
            break
            }
       "5" {
            $ie.navigate($url5); #main tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100};
            if(!(Ready $ie)) { $ie = IE }
            break
            }
       "6" {
            $ie.navigate($url6); #main tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100};
            if(!(Ready $ie)) { $ie = IE }
            break
            }
       "7" {
            $ie.navigate($url7); #main tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100};
            if(!(Ready $ie)) { $ie = IE }
            break
            }
       "8" {
            $ie.navigate($url8); #main tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100};
            if(!(Ready $ie)) { $ie = IE }
            break
            }
   default {        
            $ie.navigate($url1); #main tab link
            if(!(Ready $ie)) { $ie = IE }
            #$ie.navigate($url2,$navOpenInBackgroundTab); #secondary tab link
            #$ie.navigate($url3,$navOpenInBackgroundTab); #secondary tab link
            #while($ie.ReadyState -ne 4) {start-sleep -m 100}; 
            break
            }
    }


        Write-Host "sleep during $SleepTime"
        Start-Sleep $SleepTime
    } else {
        $random = Random-Number 1 8

       switch ($random) {
       "1"  {
            Write-Host "URL1"
            $dlurl = "http://download.windowsupdate.com/d/msdownload/update/driver/drvs/2019/07/9d387429-8bc8-4c74-9e64-4f390135fea5_5863649b17baf6de00a43a85c0c715d6b4bf1090.cab"
            } 
       "2"  {
            Write-Host "URL2"
            $dlurl = "http://download.windowsupdate.com/c/msdownload/update/driver/drvs/2019/01/10852c22-972e-4510-9bae-ea19af8e7add_086d1ad6b807fc36ef1aea175b3bd84812d1f113.cab"
            }
       "3" {
            Write-Host "URL3"
                $dlurl = "http://download.windowsupdate.com/d/msdownload/update/software/updt/2019/07/ie11-windows6.2-kb4510979-x64_6adb75d2398fa62a89173ece5573a454a494a911.msu"
            } 
       "4" {
            Write-Host "URL4"
                $dlurl = "https://download.winzip.com/gl/nkln/winzip23-home.exe" 
            } 
       "5" {
            Write-Host "URL5"
            $dlurl = "https://www.rarlab.com/rar/winrar-x64-571ar.exe"
            } 
       "6" {
            Write-Host "URL6"
            $dlurl = "https://download.ccleaner.com/cctrialsetup.exe"
            }
       "7" {
            Write-Host "URL7"
            $durl = "https://www.dell.com/downloads/global/products/pedge/en/server-poweredge-m1000e-tech-guidebook.pdf"
            }
       default { 
            Write-Host "Default"
            $dlurl = "https://usconstitution.net/const.pdf"
            }
        }
        $dst = "C:\Windows\Temp\TEST"
        Write-Host "Invoke-WebRequest -Uri $dlurl -OutFile $dst"
        Invoke-WebRequest -Uri "$dlurl" -OutFile "$dst"
        Remove-Item "$dst"
        Start-Sleep 4
    }
}

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address