Jump to content
u0m3

Automatizare FileList 10th Year Anniversary Gift

Recommended Posts

Cu ocazia aniversarii a zece ani de FileList, au decis sa lanseze mai multe surprize, unda dintre acestea fiind:

Quote

10th anniversary gift! Începând cu 04 septembrie până în 11 septembrie inclusiv, o dată la 24 de ore puteți da click pe cadoul din stânga paginii și veți primi un cadou din partea site-ului. Cadoul este similar cu gift box-ul din Shop și puteți câștiga: Upload, FLCoins, Invitații, FLTokens, VIP.

Toate bune si frumoase, doar ca, daca esti tampit ca mine si ai gasit prima data giftbox-ul la ora 5 dimineata (sau pentru oamenii normali, esti ocupat) si nu ai cum sa verifici la 24 de ore, vei pierde din premii*.

Si cum suntem cu totii 0xH4X0R1 pe aici am decis sa fac un mic script in PowerShell (daca am chef/rabdare il voi face si in Python) care sa se ocupe de problema:

Spoiler

function Get-FileListLogin
{
    Param
    (
        [parameter(Mandatory=$true)]
        [String] $Username,
        [parameter(Mandatory=$true)]
        [String] $Password,
        [parameter(Mandatory=$false)]
        [Int] $Unlock = 1
    )

    Process
    {
        $requestBody = @{
            username = $Username;
            password = $Password;
            unlock = $Unlock;
        };
        $webRequest = Invoke-WebRequest -Uri 'https://filelist.ro/takelogin.php' -Method Post -Body $requestBody -SessionVariable session -Verbose;
        if ($webRequest.StatusCode -eq 200)
        {
            Write-Debug -Message 'Loggin succesfull. Returning session variable.';
            return $session;
        }
        else
        {
            Write-Debug -Message "Failed to login $($webRequest.StatusCode): $($webRequest.StatusDescription).";
            return $false;
        }
    }
}

function Get-FileListGift
{
    Param
    (
        [parameter(Mandatory=$true)]
        $Session
    )

    Process
    {
        $webRequest = Invoke-WebRequest -Uri 'https://filelist.ro/gift.php' -Method Get -MaximumRedirection 0 -WebSession $Session -Verbose;
        if ($webRequest.StatusCode -eq 200)
        {
            Write-Debug -Message 'Request succesfull. Returning raw content.';
            return $webRequest.RawContent;
        }
        elseif (($webRequest -ge 300) -and ($webRequest -lt 400) -and ($webRequest.Headers.Location -eq '/login.php'))
        {
            Write-Debug -Message 'Request failed. You need to login.';
            return $false;
        }
        else
        {
            Write-Debug -Message "Request failed with code $($webRequest.StatusCode): $($webRequest.StatusDescription). Returning request response.";
            return $webRequest;
        }
    }
}

function Invoke-FileListGetGift
{
    Param
    (
        [parameter(Mandatory=$true)]
        [String] $Username,
        [parameter(Mandatory=$true)]
        [String] $Password,
        [parameter(Mandatory=$false)]
        [Int] $Unlock = 1
    )

    Process
    {
        $doLoop = $true;
        $session = $false;

        while ($doLoop)
        {
            if ($session -eq $false)
            {
                $session = Get-FileListLogin -Username $Username -Password $Password -Unlock $Unlock;
            }

            $ret = Get-FileListGift -Session $session;
            if ($ret -eq $false)
            {
                $session = $false;
            }
            elseif ($(Get-TypeName -InputObject $ret) -eq 'HtmlWebResponseObject')
            {
                Write-Debug -Message "'Get-FileListGift' returned a 'HtmlWebResponseObject'.";
            }
            elseif ($(Get-TypeName -InputObject $ret) -eq 'String')
            {
                $sleepSeconds = 0;
                if ($ret -cmatch '(?i)You already claimed a gift in the last 24 hours! Please check back again in (?<hours>\d+)h (?<minutes>\d+)m (?<seconds>\d+)s.')
                {
	                $hours = $matches['hours'];
                    $minutes = $matches['minutes'];
                    $seconds = $matches['seconds'];
                    $sleepSeconds = ((($hours -as [Int])*60 + ($minutes -as [Int]))*60 + ($seconds -as [Int]));
                    Write-Host -Object $matches[0];
                }
                elseif ($ret -cmatch '(?i)You won (?<prize>.*)!')
                {
                    $sleepSeconds = 24*60*60;
	                Write-Host -Object $matches[0];
                }
                else
                {
                    Write-Debug -Message "Whoops! Page did not say we won nor did it say we need to wait... Strange... Here is the content:";
                    Write-Debug -Message $ret;
                }
                Write-Host -Object "Sleeping for $sleepSeconds seconds...";
                Start-Sleep -Seconds $sleepSeconds;
            }
            else
            {
                Write-Debug -Message "This should have never reached. Get-TypeName -InputObject `$ret -FullName = $(Get-TypeName -InputObject $ret -FullName)";
            }
        }
    }
}

 

Mod de utilizare:

  • Copy - Paste la cod intr-o fereastra de PowerShell apoi rulati Invoke-FileListGetGift.
  • Salvati codul intr-un fisier *.ps1 apoi din PowerShell ii faceti source: adica scrieti in consola ". .\NumeFisier.ps1" (atentie la punctul din fata - e ca la bash) apoi rulati Invoke-FileListGetGift.

Daca doriti sa vedeti mesajele de debug setati $DebugPreference = "Continue" in consola din care rulati apoi apelati Invoke-FileListGetGift.

  • Upvote 9
Link to comment
Share on other sites

Versiunea Python2 dupa cum am promis. Imi cer scuze legat de calitatea codului.

Spoiler

#!/usr/bin/env python2

import cookielib
import urllib
import urllib2
import re
import time
import logging

# Config
fl_username = 'FileList_username'
fl_password = 'FileList_password'

# Globals
cj = None
opener = None

# URLS
fl_login_url = 'https://filelist.ro/takelogin.php'
fl_gift_url = 'https://filelist.ro/gift.php'

# MISC
match_regex = r"You won (?P<prize>.*)!|You already claimed a gift in the last 24 hours! Please check back again in (?P<hours>\d+)h (?P<minutes>\d+)m (?P<seconds>\d+)"


def login(username, password, unlock=1):
    # type: (str, str, bool) -> [None, False, True]
    global opener
    log = logging.getLogger('main.login')
    login_data = urllib.urlencode({
        'username': username,
        'password': password,
        'unlock': unlock
    })
    response = opener.open(fl_login_url, login_data)
    if response.code == 200:
        body = response.read()
        if body.find('User sau parola gresite.') == -1:
            log.info('Successfully logged in.')
            return True
        else:
            log.info('Failed to log in. Wrong username or password.')
            return None
    else:
        log.warn('Failed to log in. Request answered with non-200 code.')
        return False


def get_gift():
    global opener
    log = logging.getLogger('main.get_gift')
    response = opener.open(fl_gift_url)
    if response.code == 200:
        if response.url.find('login.php') != -1:
            log.info('We need to login again.')
            return False
        else:
            log.info('We have received the gift page. Returning contents for parsing')
        return response.read()
    else:
        # How did we get here? And where is HERE?
        log.warn('We have reached an unexplored zone of space-time.')
        return None


def main():
    global cj, opener
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
        datefmt='%Y-%m-%dT%H:%M:%S'
    )
    log = logging.getLogger('main')
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(
        urllib2.HTTPRedirectHandler(),
        urllib2.HTTPHandler(debuglevel=0),
        urllib2.HTTPSHandler(debuglevel=0),
        urllib2.HTTPCookieProcessor(cj)
    )
    do_loop = True
    log.info('Setup complete. Entering loop.')
    while do_loop:
        ret = get_gift()
        if ret is False:
            log.info('We were not logged in. Logging in.')
            login(fl_username, fl_password)
        elif ret is None:
            log.error('For some reason we need to exit the loop.')
            do_loop = 0
        else:
            match = re.search(match_regex, ret, re.IGNORECASE)
            if match:
                prize = match.group('prize')
                wait_hours = int(match.group('hours'))
                wait_minutes = int(match.group('minutes'))
                wait_seconds = int(match.group('seconds'))
                if prize is not None:
                    wait_hours = 24
                    wait_minutes = 0
                    wait_seconds = 0
                    log.info('Congratz! You got %s' % str(prize))
                else:
                    log.info(
                        'We need to wait %d hours %d minutes %d seconds' % (wait_hours, wait_minutes, wait_seconds)
                    )
                wait_time = (wait_hours * 60 + wait_minutes) * 60 + wait_seconds
                log.info('Sleeping for %d seconds' % wait_time)
                time.sleep(wait_time)
            else:
                # How did we end up here?!?!?!?!
                log.error('Toto, we are not in Kansas anymore!')


if __name__ == '__main__':
    main()

 

  • Upvote 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...