Tehtävä 6

h6 Final Countdown

Kysymys a: Middle. Muuta hakupyyntöä välimiesproxylla.

Käytin Windows 10 -koneeseen asennettua VMWare Workstation 15 Pro -virtuaaliympäristöä, joka koostuu virtuaalisesta lähiverkosta ja  Kali linux 22.04 virtuaalikokeesta, joka on kytketty ulkoiseen verkkoon NATin kautta.  Käytin Kali linux virtuaalikonetta Windows 10 koneelta SSH-yhteydellä.

Päätin tehdä mies-in-the-middle-hyökkäyksen PortSwigger LAB -sovellukselle. Kyseinen sovellus on tehty PortSwagger Academylle ja tarkoitettu PortSwagger Burp ohjelman koulutukseen. Käynnistin Burp Kali linux virtuaalikoneella. Burpin oma selain ei toimi hyvin minun virtuaalikoneella, joten päätin käyttää Mozilla Firefox selainta.

Firefox selaimessani on asennettu Foxyproxy laajennus, jonka avulla selaimen verkkoliikennettä voidaan ohjata tietyn portin kautta, jolla toimii Burp proxy. Avasin Burp proxyn ja Options välilehdellä vaihdoin portin asetuksia 8088:ksi

Avasin Foxyproxyn asetuksia ja loin Burp proxyn asetuksia.

Koska PortSwigger Lab käyttää HTTPS protokollaa, minun piti importoida Burp:in sertifikaatin Mozillan CA-sertifikaatiksi, jolla olisi oikeus tunnistaa sivustot. Sen jälkeen kun kaikki valmistelut oli tehty, avasin Labran ohjeet. Päästäkseen tekemään labraa pitää rekisteröityä PortSwagger Academyssa ja varmentaa sähköpostiosoitetta klikkamalla sinne saapunutta linkkiä.

Labran tehtävänä on väärentää selaimesta lähtevät sanomat. Labra on leikkiverkkokauppa, jossa voi ostaa tuotteita.

Kuten kuvasta näkee minulla on $100 rahaa. Kokeilin tilata kallimman tuotteen joka maksaa $1337. Ennen kun laitoin tuotteen ososkoriin, laitoin Burp proxyn inteceptor päälle ja sitten lisäsin tuotteen osotoskoriin. Sanoma avautunut Burp interceptorissa, jossa sitä voi muokata ja lähettää eteenpäin. Muokkasin alkuperäisen viestin lisämällä tuotteiden kappalemäärän ja pienentämällä hinnan.

 

Osotoskorissa näkynyt 6 kpl nahkatakkia, joiden yksikkähinta oli 3 senttiä/kpl. Vahvistin tilauksen ja sain vahvistuksen, että labra on suoritettu.

Johtopäätös:

Man-in-the-Middle hyökkäyksessä voi väärentää myös TLS suojattua liikennettä. Se vaatii, että hyökkäjä asentaa uhrin koneelle oman CA-varmenten. Sitä ei huoma jos ei mene katsomaan sivuston sertifikaattia tarkemmin. Ensimmäisessä kuvassa on hyökkäjän varmennus ja toisessa kuvassa on oikea labran Amazonin varmennus.

 

Lähteet:

PortSwigger. Installing Burp’s CA certificate in Firefox

PortSwigger. Modifying HTTP requests with Burp Proxy

PortSwigger. Lab: Excessive trust in client-side controls

Null byte. Use Burp & FoxyProxy to Easily Switch Between Proxy Settings

 

Tehtävä b: Cheatsheet – kerää parhaat kikat, käskyt ja tekniikat omasta ja toisten raporteista. (tässä alakohdassa pelkkä kirjoitus riittää, ei tarvitse testata koneella)

  • Tuomas Lintula. Seclist paketti. Seclist pakettia voidaan käyttää Brute force hyökkäyksissä. Paketti asentaa Linux koneelle komennolla: sudo apt-get install seclists
  • Tuomas Lintula. Hydran käyttö. Hydra on rinnakkainen sisäänkirjautumiskekseli, joka tukee useita hyökkäysprotokollia. Se on erittäin nopea ja joustava, ja uusia moduuleja on helppo lisätä.
  • Tuomas Lintula. SSH versioiden erot. Jos hyökkätään toiseen koneseen, jossa on eri SSH-palvelimen versio, niin salausteknikat eivät välttämättä sopi. Yhdistäessä on määritettävä käytettäväksi rsa salausta
  • Tuomas Lintula. EyeWitness. EyeWitness on ohjelma jonka tarkoituksena on ottaa kuvia valituista internet sivuista ja kerätä niistä hieman tietoa.

 

Tehtävä d: Kaikki tehtävät tähän. Listaa suora linkki kuhunkin palautukseesi.

Kaikki tehtäväni löytyvät blogini Penetration testing sivulta.

Alku testi

Tehtävä 1 –  Vuohi, tappoketju ja pimeän verkon päiväkirjat

Tehtävä 2 – Turbo boosted

Tehtävä 3 – Attaaack!

Tehtävä 4 – Tiedustelua

Tehtävä 5 – Script Kiddie

Tehtävä 6 – Final Countdown

 

Tehtävä 3

h3 Attaaack!

Kysymys x: Lue/katso/kuuntele ja tiivistä. Tässä alakohdassa ei tarvitse tehdä testejä tietokoneella, vain lukeminen ja tiivistelmä riittää). Tiivistä ranskalaisilla viivoilla.

  • € Percival & Samancioglu 2020: The Complete Ethical Hacking Course (video): Chapter 21: Cross Site Scripting (7 videota, noin 25 min)
  • OWASP 10 2017 (pdf) A2 Broken Authentication, A3 Sensitive Data Exposure, A7 Cross Site Scripting. (Poimi kustakin kolmesta hyökkäyksestä, miten ne käytännössä tehdään)
  • MITRE 2021: ATT&CK Enterprise Matrix. (Selitä tiivistelmässä käsitteet tactic, technique, procedure. Selitä kukin taktiikka (tactic) ja anna kustakin taktiikasta esimerkkitekniikka (technique tai subtechnique).

 

Vastaus

  • XSS eli Cross-Site Scripting on hyökkäyksen tyyppi, jolloin hyökkääjä upottaa haitallista JavaScript koodia web-palvelimelle, jota sitten suoritetaan uhrin koneella web selaimessa.
  • XSS Reflected on eräänlainen XSS-hyökkäys, jossa hyökkääjä toimittaa uhrille linkin, joka käynnistää haitallisen JavaScript-koodin uhrin selaimessa, kun sitä napsautetaan.
  • XSS Stored -hyökkäyksessä haitallinen koodi upotetaan verkkosivustoon, ja kun uhri käyttää tartunnan saaneita resursseja, haitallinen koodi suoritetaan uhrin verkkoselaimessa.
  • Sivustolle upotettu XSS-haittakoodi voi ladata haitallisen JS-koodin toisesta hyökkääjän hallinnoimasta resurssista ja suorittaa sen uhrin verkkoselaimessa.
  • Paras tapa suojautua XSS -hyökkäyksiltä on olla käymättä epäilyttävissä verkkoresursseissa tai avaamatta epäilyttäviä linkkejä.
  • Selaimessa voidaan laittaa pois päältä JavaScriptin suoritusta, mutta silloin oikeat resurssit eivät tule toimimaan oikein.

Source:

Lähde: OWASP 10 2017 (pdf)

MITRE 2021: ATT&CK Enterprise Matrix.

Tactic

Taktiikka vastaa kysymyksen miksi hyökkäystä tehdään. Se on vastustajan taktinen tavoite, eli syy toiminnan suorittamiseen.

Technique

Tekniikka esiittää kysymystä miten hyökkääjä meinaa saavuttaa taktisiä tavoitteita suorittamalla toimeenpiteita.

Procedure

Proseduurit ovat hyökkäyksen toteutuksia, joita hyökkääjä käyttää tekniikoissa.

 

Taktiikat:

Mitre ATT&CK -viitekehyksessä on useita erilaisia ​​matriiseja käyttöjärjestelmille ja verkoille sekä suurille yrityksille. Tulen tutkimaan Enterprise Matrix -taktiikoita, jossa on yhteensä 14 erilaista taktiikkaa.

 

Reconnaissance

Tiedustelu koostuu tekniikoista, joissa hyökkääjät keräävät aktiivisesti tai passiivisesti tietoa, jota voidaan käyttää kohdistamisen tukemiseen. Esimerkiksi aktiivinen skannaus (Active Scanning), jolloin hyökkääjä tutkii uhrin infrastruktuuria kerätäkseen tietoja skannaamalla verkkoa, koneita, portteja.

Resource Development

“Resurssien kehittäminen koostuu tekniikoista, joissa vastustajat luovat, ostavat tai vaarantavat/varastavat resursseja, joita voidaan käyttää tukemaan kohdistamista. Tällaisia ​​resursseja ovat infrastruktuuri, tilit tai ominaisuudet.”(Mitre) Esimerkiksi käyttäjätilien varaantaminen (Compromise Accounts) tekniikassa on Email Accounts -alitekniikka, jossa hyökkääjä vaarantaa toisen sähköpostitilin saadakseen namioitua toiseksi henkilöksi, jonka uhri tuntee ja johon hän luottaa.

Initial Access

“Initial Access koostuu tekniikoista, jotka käyttävät erilaisia sisääntulovektoreita saadakseen ensimmäisen jalansijansa verkossa. Jalansijan saamiseksi käytettyjä tekniikoita ovat kohdennettu tietokalastelu ja julkisten verkkopalvelimien heikkouksien hyödyntäminen.” (Mitre). Esimerkiksi hyökkääjät voivat lähettää phishing-viestejä päästäkseen uhrijärjestelmiin. Kaikki tietojenkalastelun muodot ovat sähköisesti toimitettuja sosiaalista manipulointia. (Mitre)

Execution

Execution taktiikka koostuu teknikoista, joissa suoritetaan hyökkäjän koodia uhrin paikallisella ta etäjärjestelmässä. Yleensi sitä yhdistetään mihin teknikoihin kuten aktiivinen skannaus. Esimerkiksi User Execution, jossa käyttäjää saadaan suorittamaan haitallista koodia esimerkiksi avaamalla haitallinen asiakirjatiedosto tai linkki, joka oli lähetetty uhrille kalasteluviestissä.

Persistence

Pysyvyys koostuu tekniikoista, joita käytetään säilyttääkseen jalanjälkiä järjestelmässä sen uudelleen käynnistyksen, muutuneiden käyttäjätunnusten tai muun keskeytyksen takia. Esimerkiksi Account Manipulation tekniikassa hyökkääjä voi luoda uusia käyttäjätunnuksia järjestelmään, joita se voi käyttää päästäkseen sinne keskeytyksen jälkeen.

Privilege Escalation

Oikeuksien eskalointi koostuu menetelmistä, joita hyökkääjät käyttävät hankkiakseen korkeamman tason käyttöoikeuksia järjestelmässä tai verkossa. Esimerkki tekniikka on Access Token Manipulation, jossa hyökkäjät voivat muokata käyttöoikeuksia toimimaan eri käyttäjän tai järjestelmän suojauskontekstissa toimintojen suorittamiseksi ja pääsynvalvonnan ohittamiseksi.

Defense Evasion

Defence Evasion koostuu tekniikoista, joita vastustajat käyttävät välttääkseen havaitsemisen koko hyökkäyksen ajan. Tämä tekniikka käyttää monia samoja tekniikoita kuin ePrivilege Escalation taktiikassa. Esimerkiksi Build Image on Host tekniikassa hyökkäjä voi rakentaa oman konteinerin kohdekoneella, josta voi pysyä piilossa ja jatkaa hyökkäystä.

Credential Access

Credential Access koostuu tekniikoista, joilla varastetaan tunnistetietoja, kuten käyttäjätunnuksia ja salasanoja. Esimerkki tekniikka on Brute force, jolloin tunistetietoja saadaan arvaamalla salasanoja käyttämällä toistuvaa tai iteratiivista mekanismia.

Discovery

Discovery koostuu tekniikoista, joita hyökkääjä voi käyttää saadakseen tietoa järjestelmästä ja sisäisestä verkosta. Esimerkiksi Account Discovery tekniikassa hyökkäjä voi tutkia mitkä käyttäjätunnuksia löytyy järjestelmässä tai ympäristössä.

Lateral Movement

Lateral Movement koostuu tekniikoista, joita hyökkääjät käyttävät päästäkseen verkon etäjärjestelmiin ja ohjaamaan niitä. Ensisijaisen tavoitteensa saavuttaminen vaatii usein verkoston tutkimista kohteen löytämiseksi ja sen jälkeen pääsyn siihen. Esimerkki on Exploitation of Remote Services tekniikka, jossa käytetään hyväkseen ohjelmistojen haavoituvuuksia asentamaalla exploitit kohdejärjestelmään.

Collection

Collection taktiikka koostuu tekniikoista, joissa hyökkääjät voivat kerätä tietoja tavoitteiden saavuttamiseksi. Hyökkääjät voivat käyttää Input Capture tekniikkaa ja sen Keylogging -alitekniikkaa, joka kaappaa kohdekoneen näppäinpainallukset ja tallentaa ne myöhempää käyttöä varten.

Command and Control

“Command and Control koostuu tekniikoista, joita vastustajat voivat käyttää kommunikoidakseen hallinnassaan olevien järjestelmien kanssa uhriverkon sisällä. Vastustajat yrittävät yleensä jäljitellä normaalia odotettua liikennettä havaitsemisen välttämiseksi.” Esimerkki tekniikka on Encrypted Channel. Hyökkääjät voivat käyttää salattua kanavaa kätkeäkseen käsky- ja ohjausliikennettä.

Exfiltration

Exfiltration koostuu tekniikoista, joiden avulla hyökkääjä voi siirtää varastettuja tietoja järjestelmästä itselleen käyttämällä tietojen salausta ja arkistointia ennen datan siirtoa vältäkseen havaitsemista ja kiinni jäämistä. Esimerkiksi Exfiltration Over Other Network Medium tekniikassa hyökkääjät voivat lähettää varastettuja tietoja käyttämällä vaihtoehtoista yhteyttä, kuten WiFi, Bluetooth tai RF, jos sellainen on olemassa kohdekoneessa.

Impact

Impact-taktiikassa hyökkääjät voivat yrittää tuhota, häiritä tai manipuloida kohdejärjestelmää tai sen tietoja. Esimerkki on Network Denial of Service, jossa voidaan suorittaa DDoS hyökkäystä estääkseen kohdistettujen resurssien saatavuutta käyttäjille.

Lähteet:

Mitre ATT&CK. FAQ

Kysymys z: Cross site story. Kirjoita kuvitteellinen esimerkki XSS-hyökkäyksestä. Tee mahdollisimman yksinkertainen esimerkki. Voit vaikkapa ottaa haltuun weppisivun ylläpitäjän oikeudet viemällä keksin. Tässä alakohdassa ei tarvitse tehdä mitään tietokoneella, pelkkä tarina riittää. Tarkoituksena on ymmärtää XSS-hyökkäyksen kokonaisuus ennen sormiharjoituksia. Voi halutessasi myös piirtää itse kaavion / sarjakuvan.

Tee selväksi ja erottele

  • Mitä hyökkääjä tekee
  • Mitä kohdehenkilö tekee
  • Mitä sivua / palvelinta kohdehenkilö surffailee
  • Missä JavaScriptit ajetaan
  • Miten keksi päätyy hyökkääjälle
  • Miten hyökkääjä hyödyntää keksiä?
  • Mitä hyökkääjä pääsee tekemään (mikä ei onnistuisi ilman hyökkäystä)?

Cross site story: XSS Key logger hyökkäys.

Hyökkääjän tavoitteena on varastaa muiden ihmisten luottokorttitiedot ja käyttää niitä rikolliseen hyötyyn.

Hyökkääjä löytää XSS haavoittuvuuden sivustolla, jossa käyttäjät syöttävät henkilökohtaisia tietoja kuten luottokortitietoja esimerkiksi verkkokaupan. Hyäkkääjä luo oman palvelimen ja asentaa sinne yksinkertaisen JavaScript koodin, joka poimii näppäinten painaluksia ja välittää niitä hyökkäjän palvelimella olevaan teksitiedostoon. Hyökkääjä upottaisi haavoittuvaiselle sivulle toisen JavaScript-koodin, joka latautuisi uhrien selaimiin, kun he käyttävät palvelua. Tämä JavaScript-koodinpätkä kutsuu hyökkääjän koneessa olevaa skriptiä, joka välittää kaikki käyttäjän tekemät näppäinpainallukset hyökkääjän palvelimella olevaan tekstitiedostoon.

Uusi käyttäjä vierailee verkkokaupassa. Haitallinen koodi on upotettu verkkokaupan etusivulle, joten heti sisäänkirjautumisen jälkeen käyttäjän selain suorittaa sen ja alkaa lähettämään tietoja hyökkääjälle. Jotta käyttäjä voi tilata tuotteita verkkokaupasta, hänen pitää syöttää luottokorttitietonsa palveluun. Haitaohjelma lähettää kaikki näppäinten painaluksia hyökkäjälle ja mm. luottokortin tiedot.

Hyökkääjä voi käyttää vastaanottamiaan luottokorttitietoja ja tilata tavaroita muista verkkokaupoista ja palveluista.

Tämä XSS-hyökkäys ei käytä evästeitä, koska ne eivät kiinnosta hyökkääjää. Kyseessä on XSS Stored hyökkäys.

 

 

Lähde:

Web Security Store. 5 Real-World Cross Site Scripting Examples

 

 Tee ja raportoi

a) Vuohen uudet seikkailut. Ratkaise WebGoatista tehtävät

  • A2 Broken authentication:
    • Authentication bypasses: 2 2FA Password Reset
  • A3 Sensitive data exposure
    • Insecure Login: 2 Let’s try
  • A7 Cross Site Scripting (XSS): Cross site scripting
    • 2 What is XSS?
    • 7 Try It! Reflected XSS
  • A8:2013 Request Forgeries:
    • Cross-Site Request Forgeries
      • 3 “Basic Get CSRF Exercise”
      • 4 “Post a review on someone else’s behalf”.

Raportti

Käytin Windows 10 -koneeseen asennettua VMWare Workstation 15 Pro -virtuaaliympäristöä, joka koostuu virtuaalisesta lähiverkosta ja  Kali linux 22.04 virtuaalikokeesta, joka on kytketty ulkoiseen verkkoon NATin kautta.  Käytin Kali linux virtuaalikonetta Windows 10 koneelta SSH-yhteydellä.

Käynnistin WebGoat Version 8.0.0.M26 sovelluksen Ubuntu 18.04 vituaalikoneella seuraavalla komennolla:

$ java -Dfile.encoding=UTF-8 -jar webgoat-server-8.0.0.M26.jar

Syötin WebGoat sovelluksen URL-osoitteen (htp://localhost:8080/WebGoat/) selaimeen. WebGoat sovellus avautui selaimessa.

Tehtävä A2: Broken authentication:

  • Authentication bypasses: 2 2FA Password Reset

Tehtävässä pitänyt ohittaa MFA tarkistukysymyksillä. Tähän tehtävän suorittamiseen tarvitsen proxy:a. Asensin Kali koneelle OWASP ZAP ja Foxyproxy FireFox selaimen laajennuksen.

$ sudo apt -y install zaproxy

Valitsin FoxyProxy laajennuksessa ZAP, niin kaikki selaimen verkkoliikenne ohjautuisi ZAP Proxyn kautta.

Avasin ZAP Proxyn ja laitoin interceptor päälle, jotta sanomat jäisivät proxylle.

Syötin WebGoat sovellukseen vapavalinnaiset vastaukse tarkistukysymyksiin ja painoin Submit.

POST pyyntö tuli ZAP:iin.

Avasin sanoman editorissa ja korjaasin muuttujien nimet lisämällä muutaman nollaan.

Vastauksena tuli onnittelut, että tili on todennettu ja pystyn vaihtaa salasanaa. Tehtävä on suoritettu.

Pyyntöjä sovelluksen back-end:ille voidaan muokata selaimessa Developer modessa tai Proxylla. Sovelluksessa pitää toteuttaa ohjelmallinen tarkistus muuttujien nimille ja määrälle. PenTestauksessa pitää etsiä tämän tyyppisiä havoittuvuuksia, koska niitä on suhtellisen helppoa käyttää hyväkseen ja havaita.

Source: https://www.youtube.com/watch?v=Og3vNKnUSac

Tehtävä A3: Sensitive data exposure

  • Insecure Login: 2 Let’s try

Tehtävässä pitää napata salamattomasta verkkoliikenteestä sanoman, joka sisältää käyttäjätunnuksen ja salasanan.

Päätin käyttää Burp ohjelmaa jossa on myös proxy ominaisuus. Se on asennettuna Kali linux distroon, mutta sen käynnistämiseen pitänyt antaa agrumentit. Käynnistin sen seuraavalla komennolla (yhteen riviin):

$ java -jar –add-opens=java.desktop/javax.swing=ALL-UNNAMED –add-opens=java.base/java.lang=ALL-UNNAMED /usr/share/burpsuite/burpsuite.jar

Piti ohjata Firefox selaimen liikennettä Burp proxyn kautta. Tarkistin asetuksissa millä portilla Burp proxy toimii.

Avasin FoxyProxyn asetukset ja lisäsin sinne Burp IP-osoitten ja portin.

Sen jälkeen valitsin FoxyProxy laajennuksen valikosta luomaani Burp proxyn ja verkkoliikenne ohjautui kulkemaan Burpin kautta. Laitoin Burp proxyn interceptor päälle, jotta sanomat eivät välityisi eteenpäin ja pystyisi kontroloimaan niiden lähetystä.

Tehtävässä pitänyt painaa Log in paineketta ja selaimesta lähti pyyntö palvelimelle. Paluusanomassa pitänyt tulla käyttäjätunnus ja salasana. Painoin painiketta ja Burp nappasi muiden sanomien joukossa salamattoman paluusanoman, koska liikenne tapahtuu HTTP-protokollalla, joka ei ole salattu.

Syötin onnistuneesti tiedot sisäan ja sain varmistuksen, että tehtävä on suoritettu.

Lähteet:

Null byte. Use Burp & FoxyProxy to Easily Switch Between Proxy Settings

Tehtävä A7: Cross Site Scripting (XSS): Cross site scripting

  • 2 What is XSS?

Tehtävän ohjeet eivät toimineet Firefox selaimessa. Onneksi opettajamme antoi vinkin tehtävän suorittamiseen. “A7:2017 Cross Site Scripting: JavaScript-bookmarkletit eivät oletuksena toimi enää monissa selaimissa, käytä JavaScriptin ajamiseen F12 Console. Cross Site Scripting: script-tagit. “Try It! Reflected XSS” on läpi, kun yllä numeron tausta muuttuu vihreäksi, vaikka se sanoo “Well done, but … Please continue.”.” Joten avasin selaimen Developer mode painamalla F12 ja siirryin Console välilehdelle. Siellä kirjoitin alert(document.cookie); ja painoin Enter. Ruudulle ponnahti Alert ikkuna jossa oli istuntoeväste.

Tehtävän tarkoituksena oli vertailla WebGoat-sovelluksen istuntoevästeitä kahdella eri selaimen välilehdellä. Avasin toisen välilehden, jossa avasin saman WebGoat-sovelluksen ja suoritin konsolissa saman komennon kuin ensimmäisessä välilehdessä. Näytölle ilmestyi varoitusikkuna, jossa oli sama istuntoeväste kuin toisessa välilehdessä. Siten voidaan todeta, että istuntoeväste ei muutu. Syötin yes vastauksen tehtävän kysymykseen. Tehtävä on suoritettu.

Minua jäänyt vaivamaan kysymys, miten varastamalla istuntoevästettä, voi käynnistää sessiota toisella koneella. Päätin tarkistaa onko session cookie sama toisessa selaimessa. Asensin Chromium selain ja käynnistin WebGoat siinä. Istuntoeväste oli toinen.

Ilmeisesti Firefox ja Chrome selaimet säilyvät istuntoevästeet eri paikoissa. Firefox käyttää SQLite tietokantaa tähän, joka sijaitsee käyttäjän profiilissa ~/.mozilla/firefox/<profile path>/cookies.sqlite

Istuntoevästettä voi muokata selaimessa Developer mode Storage välilehdellä. Chrome selaimessa kanssa pystyy muokkamaan istuntoevästettä Developer mode tilassa.

 

Lähteet:

StackExchange. Where does Firefox store its cookies on Linux?

Chrome Developers. View, edit, and delete cookies

Kali. Chromium

The SSL Store. The Ultimate Guide to Session Hijacking aka Cookie Hijacking

 

  • 7 Try It! Reflected XSS

Tehtävänä oli selvittää, mikä syöttökenttä on alttiina XSS-hyökkäykselle. Koska syöttökenttä on osa HTML-dokumenttia, JS-koodi on syötettävä <script> -tagien ympäröimänä. Tein yksinkertaisen Script-komennon ja kirjoitin sen alimpaan kenttään, mutta se kenttä vastusti XSS-hyökkäystä. Kirjoitin sen toiseen alakenttään, Alert -ikkuna ponnahti istuntoevästeen kanssa, ja WebGoat sanoi, että tehtävä on tehty.

Script: <script>alert(document.cookie)</script>

 

Tehtävä A8: 2013 Request Forgeries:

  • Cross-Site Request Forgeries
    • 3 “Basic Get CSRF Exercise”
    • 4 “Post a review on someone else’s behalf”.

Basic Get CSRF Exercise -tehtävässä piti lähettää Submit Query -lomake toiselta koneelta, ja vastausviesti sisälsi tehtävän vastauksen.

Aloitin helppommalta. Avasin Firefox Developer mode -tilaan, löysin lomakken HTML -elementit.

Loin HTML -tiedoston joka sisälsi vain tämän kohdan. Lisäsin action elementiin WebGoat sovelluksen sijainnin, eli localhost:8080. WebGoat on Java MVC sovellus, mikä käy ilmi URL-osoitteesta. MVC sovelluksissa Controller hoitaa navigoinnin ja kokonaista URL-osoiteetta ei tarvitse manita. Koska tulen lähetttämään lomakkeen sovelluksen ulkopuolelta  pitää mainita polkua palvelimelle.

Tehtävän URL-osoite: http://localhost:8080/WebGoat/start.mvc#lesson/CSRF.lesson/2

Avasin tiedoston selaimessa ja painoin painikkeen.

Vastuksena tuli viesti tehtävävastauksen kanssa.

Viesti lähetettiin samasta selaimesta, jossa WebGoat-sovellus avattiin, ts. samalla istuntoevästeellä. Halusin lähettää viestin toisesta työkalusta. Ohjasin verkkoliikennettä menemään Burp:in kautta. Nappasin sanoman, joka oli lähetetty WebGoat sovelluksesta. Kyselyssä löytyy istuntoeväste ja parametrit csrf=false&submit=Submit&Query

Asensin Postman ohjelman, jolla pystyy lähettämään sanomia. Latasin Postman postman-9.16.0-linux-x64.tar.gz arkiston, avasin ja käynnistin sen.

$ tar -xvzf postman-9.16.0-linux-x64.tar.gz

$ cd Postman

$ ./Postman %U

Postman ohjelma avautunut ja loin uuden POST kyselyn, johon laitoin session cookie ja parametrit. Lähetin sen ja sain vastuksen.

Tehtävä on suoritettu.

 

Tehtävässä 4 “Post a review on someone else’s behalf”. piti lähettää kommentti blogiin toisen henkilön puolesta, toisin sanoin käyttää sen istuntoevästettä.

Lähetin kommentin sivustolle, jolloin Burp oli päällä. Se nappasi sanoman, josta sain selville pakolliset attribuutit ja istuntoevästeen.

Loin pyynnön Postman ohjelmassa toisella tekstillä istuntoevästettä käyttäen.

 

Tehtävä on suoritettu

Lähteet:

Postman. Download Postman app

Postman Learnig Center. Installing Postman on Linux

Postman. Using cookies

 

Kysymys b: Attakin alatekniikat.

Demonstroi kaksi (2) alatekniikkaa (subtechnique) ATT&CK kehikosta. Tässä pitää siis käyttää näitä käytännössä johonkin harjoitusmaaliin. Voit käyttää haluamiasi valmiita työkaluja tai koodata / skriptata itse. Voit valita valmiin harjoitusmaalin tai tehdä sen itse. Muista, että myös tiedustelussa pitää noudattaa lakia, etiikkaa, rajauksia (scope) ja hyviä tapoja.

  1. Taktiikka Reconnaissance. Tekniikka Active Scanning. Alatekniikka  Vulnerability Scanning.

Havoittuvuuksien skannauksella etsitään havoittuvuuksia kohdekoneelta. Ne voivat olla vanha käyttöjärjestelmän tai ohjelmiston versiot, auki olevat portit, palvelin bannerit, jne.

Skannan Metasploitable 2 koneetta ja käytän tähän Nmap ohjelmaa. Aloitin versioiden skannauksesta. Koneelle asennettujen ohjelmien versiot voivat kertoa paljon. Jos jonkun palvelun versio on vanha, on todennäköistä, että sillä on havoittuvuuksia. Sen saa selville etsimällä netistä palvelun nimellä ja versiolla.

Nmap skanneria voi käynnistää skriptin kanssa. Nmap:lle löytyy paljon skripteja eri tarkoituksiin. Käynnistin Nmapin vuln skriptin kanssa joka tarkistaa havoittuvuuksia ja tulostaa ne selitteineen. Listasta tuli tosi iso, niin luettelen tässä vain muutaman. Metasploitable 2 koneella on paljon havoittuvuuksia Nmap antanut CVE-numero, joiden avulla voidaann löytää valmiin exploitin tai tieto miten havoittuvuutta voidaan käyttää.

$ sudo nmap -sV –script vuln 192.168.142.134

Skanneri löytänyt mahdollisesti SQL injektiolle haavoituvan taulukon ja mainitsi jopa Input -kentän

| Possible sqli for forms:
| Form at path: /mutillidae/index.php, form’s action: ./index.php?page=user-info.php. Fields that might be vulnerable:
|_ username

HTTP enumerator skannasi web-palvelin polut, Stored XSS havoittuvuuksia ei löytynyt.

| http-enum:
| /tikiwiki/: Tikiwiki
| /test/: Test page
| /phpinfo.php: Possible information file
| /phpMyAdmin/: phpMyAdmin
| /doc/: Potentially interesting directory w/ listing on ‘apache/2.2.8 (ubuntu) dav/2’
| /icons/: Potentially interesting folder w/ directory listing
|_ /index/: Potentially interesting folder
|_http-stored-xss: Couldn’t find any stored XSS vulnerabilities.

…..

Nmap löysi paljon CSRF havoittuvuuksia, joita kokeilin aiemmin tässä tehtävässä.

| http-csrf:
| Spidering limited to: maxdepth=3; maxpagecount=20; withinhost=192.168.142.134
| Found the following possible CSRF vulnerabilities:
|
| Path: http://192.168.142.134:80/dvwa/
| Form id:
| Form action: login.php
|
| Path: http://192.168.142.134:80/mutillidae/index.php?page=text-file-viewer.php
| Form id: id-bad-cred-tr
| Form action: index.php?page=text-file-viewer.php
|
| Path: http://192.168.142.134:80/mutillidae/index.php?page=dns-lookup.php
| Form id: iddnslookupform
| Form action: index.php?page=dns-lookup.php
|
| Path: http://192.168.142.134:80/mutillidae/index.php?page=user-info.php
| Form id: id-bad-cred-tr
| Form action: ./index.php?page=user-info.php
|
| Path: http://192.168.142.134:80/mutillidae/index.php?page=html5-storage.php
| Form id: idform
|_ Form action: index.php?page=html5-storage.php

……

Näillä tiedoilla hyökkäjä voi valita kohteen koneella, johon pitää keskittää voimia hyökkäyksessä.

Lähteet:

GeekFlare. How to Use Nmap for Vulnerability Scan?

Nmap. Nse Usage and Examples

 

2. Taktiikka Persistence. Tekniikka Create Account. Alatekniikka  Local Account

Hyökkääjät voivat luoda tilin säilyttääkseen pääsyn uhrijärjestelmiin. Riittävällä käyttöoikeustasolla tällaisten tilien luomista voidaan käyttää toissijaisten käyttöoikeustietojen luomiseen, jotka eivät vaadi jatkuvan etäkäyttötyökalun käyttöönottoa järjestelmässä.

Muistan edellisestä tehtävästä, että Metasploitable 2 on auki root shell portilla 1524. Käytän sitä päästäkseen koneelle ja luodakseen käyttäjätilin.

Tarkistan onko tili luotu /etc/passwd tiedostosta.

Olisi hyvää antaa käyttäjälle sudo oikeudet, mutta en onnistunut tallentamaan tiedostoa, koska en tunne Netcat shell komennot

# visudo

Kokeilin generoida käyttäjälle Spy ssh-avaimia, jotta pystyy kirjautumaan SSh-yhteydellä. Sekin ei onnistunut.

 

3. Taktiikka Resource Development. Tekniikka Establish Accounts. Alatekniikka  Social Media Accounts

Tässä alateknikassa hyökkääjät voivat luoda ja kehittää sosiaalisen median tilejä, joita voidaan käyttää kohdistamisen aikana. Tilejä voi olla monta ja useammassa sosiaalimedian platformilla kuten Facebook, Twitter, LinkedIn. Sosiaalisen median persoonallisuuden luominen saattaa edellyttää lisädokumentaation kehittämistä, jotta he näyttävät aidolta.

 

 

Homework 7

h7 Final Countdown

Task a: Find a block and a transaction in BitCoin public ledger and explain its key parts.

 

I tried to find information about Bitcoin blocks using Google search engine and the phrase “bitcoin block explorer”. Google gave me a link to the Blockchain.com web resource, where I can get up-to-date information about blocks and transactions. Blockchain.com publishes information about new blocks, the number of block confirmations, transactions in them, as well as transaction sizes and rewards for block creation.  As you can see in the picture, the intervals for creating blocks are not the same. Sometimes new blocks are created a few minutes after the previous one, sometimes it may take longer. There is also information about the block number and its creator, if the name is known, these are usually large pools of miners.

I opened one of the blocks, I saw information about the time of block creation, who created the block and how many confirmations of its creation. It shows how much remuneration was paid to the creator, which, consists of a reward for creating a block and a commission fee. There is also information about the number of transactions in the block, their total amount in bitcoins and in US dollars.

Below is the information about the block and Hash of the block as a confirmation of the performed calculations, which starts with a certain number of zeros. There is also a Nonce number, so that everyone can make sure that the Hash calculations are carried out correctly, as well as a Merkle root Hash that indicates the initial block in the blockchain chain, with which the validity of the block can be checked.

There is also the complexity of calculations, which varies depending on the current capacity of all mining resources, so that the block is found on average once every 10 minutes.

The transactions included in the block are listed below, there are 1021 of them in this block. Each transaction has a Hash. Using the Hashes of all transactions, previous block Hash and the Nonce number, the Hash of the new block is calculated.

In the first place is the transaction to the creator of the block, which consists of a reward for creating a block and a commission fee. As we can see, in the first transaction of the block there is no wallet from which Bitcoins were transferred. Instead, it says “COINBASE (NewlyGenerated Coins)”, which means these are newly created Bitcoins.

In the second transaction, we see that bitcoins from eight addresses were transferred to two addresses. As you know, Bitcoins cannot simply be merged, for this you need to create new Bitcoins. It seems to me that in this case, the coins received from several previous transactions merge together.

By clicking on one of the addresses, I got to the page of this address, where you can see the number of transactions made using this address, their amount, the balance of coins on the address. This is a fairly large investor or trader, since the sum of all transactions in terms of US dollars is more than 3 trillion, and the current balance is $82,849,931.77. It is quite unusual in a world where banking secrecy exists to see the balance on the account of other persons or organizations. However, it should be noted that the Bitcoin address is anonymous, unless the owner has published it. The user can make as many addresses as he wants.

Below are the latest transactions of this address. As we can see, one transaction is not confirmed, and the second is confirmed only twice. The more confirmations of the transaction by other nodes of the Bitcoin network, the more reliable the transaction is.

By opening one transaction, you can see that the transfer was made from two addresses, some of the coins went to one address, and the other returned to one of the sender’s addresses as change. Thus, I can assume that both addresses from which the transaction was made belong to the same user.

In conclusion, I would like to note that it was quite interesting to watch real transactions and blocks. Before starting this course at university, I had no idea how Bitcoin works. Now I’m pretty well versed in the concepts of cryptocurrencies and this is all thanks to the materials I studied under the clear guidance of our teacher Tero Karvinen

 

Sources:

Wikipedia. Merkle tree

Investopedia. Merkle Root (Cryptocurrency)

Blockchain.com. Explorer

Felten et al 2015: Bitcoin and Cryptocurrency Technologies

 

Tehtävä 4

h4 Tiedustelua

Tee ja raportoi:

Miten nmap toimii? Tee nmapilla seuraavat testit, sieppaa liikenne snifferillä (wireshark) ja analysoi tulokset. Tee testit mahdollisimman suppeasti, jotta analysointi on helpompaa. Esimerkiksi skannaa vain yksi portti yhdestä koneesta, jos ominaisuuden esittely ei hyöydy laajemmasta skannauksesta. Selitä myös, miksi nmap lähettää tuollaisia paketteja. Käytä nmap:ia normaalisti sudo:n kanssa. Kannattaa tietysti aloittaa lukemalla man-sivulta tai Nmap Reference Guidesta, mitä noilla toiminnoilla on ylipäänsä tarkoitus tehdä. Porttiskannaa ainoastaan omaa konetta omassa verkossa ja harjoitusmaaleja.

Analyysi ja selittäminen on tärkeää. Toki tarvitaan ote snifferin lokista, komento ja ote sen tulosteesta, mutta ne eivät riitä ilman selitystä.

 

Raportti:

Tetävässä käytin Windows 10 läppäriä, jonne on asennettu VMWare Workstation Pro 15 virtuaalinen ympäristö. Ympäristö koostui Kali linuxista (hyökkääjä) ja Metasploitable 2 Ubuntu linuxista (hyökkättävä). Molemmat koneet olivat samassa virtuaaliverkossa. Käytin Kali linux konetta Windows 10 -isännästä SSH-yhteydellä MobaXtermi ohjelmaa käyttäen.

Skannasin virtuaaliverkkoa ilman porttiskannausta koska pitänyt selvittää IP-osoitteet

nmap -v -sn 192.168.142.0/24

Aktiivisia IP-osoiteita oli kolme:

192.168.142.2 – VMWare NAT

192.168.142.133 – Kali linux

192.168.142.134 – Kohde kone

Tehtävän kysymykset ja vasaukset

Kysymys a: nmap TCP connect scan -sT

TCP connect scan on oletusarvoinen TCP-skannaustyyppi, kun SYN-skannaus ei ole vaihtoehto. Sitä tehtään silloin, kun käyttäjällä ei ole raakapakettien käyttöoikeuksia (nmap sudo oikeuksilla) tai hän tarkistaa IPv6-verkkoja. Tämä on sama korkean tason järjestelmäkutsu, jota verkkoselaimet, P2P-asiakkaat ja useimmat muut verkkokäyttöiset sovellukset käyttävät yhteyden muodostamiseen. (Nmap.org)

Sama komento suoritettuna sudo oikuksilla, ei tuonnut paljon muuta informaatiota. Ainoana erona oli kohdekoneen MAC osoite

Laitoin verkkonifferin päälle Kali linux -koneella ennen nmap-komennon suorittamista. Nmap on alkanut skannamaan portteja kohdekoneella, jotka todennäköisemmin suorittavat palvelua 80, 443, 3306, jne.

Skannaus toimii näin. Portille lähetetään SYN paketin. Jos vastauksena tuli RST, ACK pakerri, niin portilla ei ole palvelua (katso portti 443 kuvassa). Jos palvelu löytyy, niin se palauttaa SYN, ACK, jonka jälkeen nmap lähettää ACK pyyntö takasin, johon vastauksena tulee SSH banner string (SSH-1.99-OpenSSH_3.1p1\n). Sen jälkeen kun yhteys on muodostettu nmap tappaa yhteyden lähettämällä RST paktin

 

Kysymys b: nmap TCP SYN “used to be stealth” scan, -sS (tätä käytetään skannatessa useimmin)

TCP SYN Scan voidaan suorittaa nopeasti skannaamalla tuhansia portteja sekunnissa nopeassa verkossa, jota häiritsevät palomuurit eivät estä. SYN-skannaus on suhteellisen huomaamaton ja vaivalloinen, koska se ei koskaan viimeistele TCP-yhteyksiä. Se toimii myös kaikkia yhteensopivia TCP-pinoja vastaan. SYN skannaus pitää suorittaa sudo oikeuksilla (katso linkki)

Filteröin Wiresharkissa vain portin 25 skannausta. Kuvästä näkee, että TCP SYN skannaus lähettää SYN paketin ja jos on saanut vastauksena SYN, ACK paketin, niin lopettaa yhteyden RST paketilla.

 

Kysymys c: nmap ping sweep -sn

Disable port scanning. Host discovery only käskee Nmapia olemaan suorittamatta porttiskannausta hostin löydön jälkeen ja tulostamaan vain käytettävissä olevat hostit, jotka vastasivat Nmapille. Tätä kutsutaan usein “ping-skannaukseksi”

-sn:llä tehty oletusisäntäetsintä koostuu oletuksena ICMP-kaikupyynnöstä, TCP SYN:stä porttiin 443, TCP ACK:sta porttiin 80 ja ICMP-aikaleimapyynnöstä. Kun etuoikeutettu käyttäjä suorittaa sen, kohteen portteihin 80 ja 443 lähetetään vain SYN-paketteja (yhteyspuhelun avulla). Kun etuoikeutettu käyttäjä yrittää skannata kohteita paikallisessa ethernet-verkossa, ARP-pyyntöjä käytetään, ellei –send-ip ole määritetty. Vaihtoehto -sn voidaan yhdistää mihin tahansa etsintäanturityyppiin (-P*-valinnat) joustavuuden lisäämiseksi.

Koska -sn skannaus skannaa IP osoitteita, sille annetaan skannattavan IP-osoitevaruuden esimerkiksi:

$ nmap -sn 192.168.142.130-139

$ nmap -sn 192.168.142.0/24

Wireshark näyttää, että Nmap lähettää Broadcastilla (kaikille verkossa oleville koneille) ARP paketin, jossa kysyy kenellä on tietty IP-osoite. Outoa, koska ohjeissa sanotaan ICMP paketista. Siellä myös sanotaan , että lokaaliverkossa skannausta tehdän ARP:lla. Teen skannausta virtuaalisessa LAN verkossa. Ilman sudoa Nmap lähettää löytyneelle konelle TCP SYN paketin, ili tekee kädenpuristuksen ja lopettaa yhteyden RST, ACK paketilla.

Sudon kanssa Nmap ei lähetä mitään paketteja havaittuun koneeseen.

 

Kysymys d: nmap don’t ping -Pn

nmap -Pn (dontät ping) Tämä vaihtoehto ohittaa isännän etsintävaiheen kokonaan. Oikea isäntähaku ohitetaan kuten luetteloskannauksessa, mutta sen sijaan, että Nmap pysäyttäisi ja tulostaa kohdeluettelon, se jatkaa pyydettyjen toimintojen suorittamista ikään kuin jokainen kohde-IP olisi aktiivinen.

kun skanataan tiettyä IP-osoitetta, niin Nmap skannaa 100 porttia.

Kun skannataan IP-osoiteiden avaruutta, niin Nmap skannaa kaikia koneita listassa

Wireshark näyttää, että ensin se yrittää kysyä DNS:ää, kenellä on skannattavat IP-osoitteet.

Sitten se alkaa skannata portteja lähettämällä TCP ACK paketteja.

 

Kysymys e: nmap version detection -sV (esimerkki yhdestä palvelusta yhdessä portissa riittää)

Service and Version Detection Nmap raportoi noin 2 200 tunnetun palvelun nmap-palvelutietokannan avulla, että kyseisellä portilla toimii tietty palvelu.

Päätin skaanata portta 80. Nmap tunnisti, että portilla toimii Apache 2.2.8 ((Ubuntu) DAV/2)

Wiresharkissa näkee, että tavallisen TCP käden puristuksen jälkeen Nmap alkaa lähettämään palvelulle HTTP GET ja POST pyyntöjä

Paketissa 63 tuli vastaus 404 Not Found. Paketissa lukee HTTP palvelimen versio

 

Kysymys f: nmap porttien valinta -p1-100, –top-ports 5, -p-

Port Selection Data and Strategies Oletusarvoisesti Nmap skannaa kunkin pyydetyn skannausprotokollan 1 000 suosituinta porttia. Tämä kaattaa noin 93 % TCP-porteista ja 49 % UDP-porteista.

nmap – 1-100 (Port range), skannaa kaikki portit tietyssä välissä.

Wiresharkista näkee, että Nmap skannaa portit 1 -100. Eli just ne portit, mitka käyttäjä tahtoo skaannata.

nmap –top-ports 5  (Port scan the top x ports)

Skannaa yleisimmät portit.

nmap -p-   ( Port scan all ports) range 1-65536

 

Kysymys g: nmap ip-osoitteiden valinta; luettelo, verkkomaskilla 10.10.10.0/24, alku- ja loppuosoitteella 10.10.10.100-130 (ipcalc auttaa ymmärtämään, miten verkkomaskia tulkitaan)

Target Specification. Käytetään kaun halutaan skaannata tiettyä verkkoa tai IP-osoitteiden avaruutta

 

Kysymys h: nmap output files -oA foo. Mihin kukin tiedostotyyppi sopii?

Output. Nmap tarjoaa ulostulon viidessä eri muodossa. Oletusarvoa kutsutaan interaktiiviseksi ulostuloksi, ja se lähetetään vakiolähtöön (stdout). Siellä on myös normaali lähtö, joka on samanlainen kuin interaktiivinen, paitsi että se näyttää vähemmän tietoa ja varoituksia ajon aikana, koska sen odotetaan jäsentävän tarkistuksen päätyttyä, eikä interaktiivisesti.

XML-tulostus on yksi tärkeimmistä tulostustyypeistä, koska se voidaan muuntaa HTML-muotoon, jäsentää helposti ohjelmilla, kuten Nmap GUI, tai tuoda tietokantoihin.

Kaksi muuta tulostustyyppiä ovat tavallisia piirrettäviä tulosteita. joka sisältää suurimman osan kohdeisäntätiedoista yhdellä rivillä ja sCRiPt KiDDi3 0utPUt käyttäjille, jotka tunnistavat itsensä |<-r4d.

nmap -oA tulostaa kolmessa päämuodossa kerralla.

Nmap tulostanut output kolmeen eri tiedostoon.

XML tarjoaa vakaan muodon, jonka ohjelmisto jäsentää helposti.

gnmap formattia on helppo käsitellä komentorivillä yksinkertaisilla Unix-työkaluilla, kuten grep, awk, cut ja diff.

nmap formatti on hyvin samanlainen kuin interaktiivinen tulos, ja se lähetetään valitsemaasi tiedostoon. Se eroaa interaktiivisesta lähdöstä useilla tavoilla, jotka johtuvat odotuksesta, että tämä tulos analysoidaan skannauksen päätyttyä, eikä interaktiivisesti.

 

Kysymys k: nmap ajonaikaiset toiminnot (man nmap: runtime interaction): verbosity v/V, help ?, packet tracing p/P, status s (ja moni muu nappi)

Nmap-toiminnon aikana kaikki näppäinpainallukset tallennetaan. Näin voit olla vuorovaikutuksessa ohjelman kanssa keskeyttämättä ja käynnistämättä sitä uudelleen. Tietyt erikoisnäppäimet muuttavat asetuksia, kun taas kaikki muut näppäimet tulostavat skannauksesta kertovan tilaviestin. (Nmap.org Runtime Interaction)

Käynnistin verkon skannauksen ja painoin ? -merkin. Ruudulle tuli Help -menu interaktiivisille komennoille.

v/V – Laajentaa ja pienentää kuvausta kannauksesta

 

d/D – Nostaa ja laskee Debug tasoa. Se tulostaa pakettien

p/P – Laittaa päälle ja pois päältä pakettien seurannan

 

Kysymys l: normaalisti ‘sudo nmap’. Miten nmap toiminta eroaa, jos sitä ajaa ilman sudoa? Suorita ja analysoi esimerkki.

Ilman sudoa Nmap skannaa:    TCP Connect (-sT)

Sudon kanssa Nmap skannaa: TCP SYN Stealth (-sS)

Lopuksi syy siihen, miksi nmap pysäyttää tarkistuksen, johtuu siitä, että IMCP Type 8 (echo a.k.a ping) ei palauta ICMP Type 0:ta (kaikuvastaus). Tämä komento ohittaa pingin ja jatka skannausta (StackExchange)

Sudon kanssa Nmap ei suorita TCP kädenpuristusta loppuun vaan keskeyttää sen RST paketilla

 

Kysymys m: nmap, vertaile -sV vs -A kestoa (ja lähetetyn datan määrää jos osaat; time, nethogs, wireshark). Käytä harjoitusmallina metasploitable2.

Nmap -A Enables OS detection, version detection, script scanning, and traceroute (Stationx. Nmap cheatsheet)

Nmap -A kestää on kaksi kertaa pidempään ja tuottaa kaksi kertaa enemmän verkkoliikennettä kuin -sV, muta myös antaa enemmän informaatiota kohdekoneesta.

 

Kysymys d: Ninjojen tapaan. Piiloutuuko nmap-skannaus hyvin palvelimelta? Vinkkejä: Asenna Apache. Aja nmap-versioskannaus -sV omaan paikalliseen weppipalvelimeen. Etsi Apachen lokista tätä koskevat rivit. Wiresharkissa “http” on kätevä filtteri, se tulee siihen yläreunan “Apply a display filter…” -kenttään. Nmap-ajon aikana p laittaa packet tracing päälle. Vapaaehtoinen lisäkohta: jääkö Apachen lokiin jokin todiste nmap-versioskannauksesta? UDP-skannaus. “Mulla olis vitsi UDP:sta, mutta en tiedä menisikö se perille”

 

Minullakin on vitsi TCP:sta, jos se ei mene perille, niin toistan sen.

Asensin Apache palvelimen näiden ohjeiden mukaan. Käynnistin Nmap -sV . Avasin lokit /var/log/apache2/access.log

Lokeista näkee, että palvelimelle tuli useampi GET pyyntö ja yksi POST eri HTTP versiolla. Kahteen Apache vastasi 200 OK, mikä on hyväksytty vastaus. Lokista näkee, että pyyntöjä lähettynyt Nmap Searching Engine, eli jälkejä jää.

Wireshark verkon kuuntelija näyttää myös vastaukset ja suurin osa niistä 404 Not found. Nmap lähettää brute force menetelmällä eri HTTP kutsut ja saadusta 200 Ok vastauksesta päättää mikä HTTP-palvelimen versio toimii portilla 80.

Yksi Nmapin pyynnöistä sai vatsuksena palvelimen version Apache/2.4.53 (Debian)

 

Kysymys e: Mitkä ovat tavallisimmat tai kiinnostavimmat palvelut, joita UDP-skannauksella voisi löytää? (tässä alakohdassa vain vastaus viitteineen, ei tarvita testiä tietokoneella)

UDP protokollalla toimivat DNS, SNMP, DHCP (rekisteröidyt portit 53, 161/162 ja 67/68) ovat kolme yleisintä, sanotaan Nmap.org sivustossa.

 

Kysymys f: Miksi UDP-skannaus on hankalaa ja epäluotettavaa? Miksi UDP-skannauksen kanssa kannattaa käyttää –reason flagia? (tässä alakohdassa vain vastaus viitteineen, ei tarvita testiä tietokoneella)

UDP Scan (-sU)

–reason flagi näytä syy, miksi portti on tietyssä tilassa, sama tulos kuin -vv (StationX. Nmap Cheat sheet) Voi olla hyödyllistä ymmärtää syy, miksi portti on merkitty avoimeksi, suljetuksi tai suodatetuksi ja miksi skannatava kone on merkitty eläväksi. Jotkut portit voivat olla tilassa open|filtered, se on ongelma UDP skannauksessa, koska avoimet UDP-portit vastaavat harvoin tyhjiin pyyntöihin. Reason flagi näyttää syyn, josta voi saada selville mikä on portin oikea tila

 

Kysymys g: Vapaaehtoinen bonuskohta: näytä esimerkki onnistuneesta UDP-skannauksesta, sekä jonkin UDP:n erityisominaisuuden takia epäonnistuneesta tai harhaanjohtavan tuloksen antavasta UDP-skannauksesta.

 

Aktiivista tiedustelua. Mihin tämä työkalu on tarkoitettu? Kokeile tätä työkalua omaan harjoitusmaaliin ja selitä tulokset:

Kysymys h: fuff (hakemistojen kokeilu riittää, vapaaehtoisena bonuksena muutakin)

Fuff tai “Fuzz Faster you Fool” on avoimen lähdekoodin web-fuzzing-työkalu, joka on tarkoitettu elementtien ja sisällön löytämiseen verkkosovelluksista tai verkkopalvelimista.

Käynnistin FFUF skannamaan Metasploitable 2 konetta. Parametrina FFUF ohjelmalle pitää antaa kohdekoneen IP-osoite tai FQDN ja sanalistan, jolla se etsii hakemistot web-palvelimella.

Tuloksena FFUF löysi mm seuraavat hakemistot:

phpMyAdmin – Koneella on asennettu PHP ja mySQL

phpinfo

tikiwiki – TikiWiki CMS

FFUF työkalu antaa kuvan mitä hakemistoja on web-palvelimella ja mitkä tiedostot ovat siellä.

 

Lähteet:

Codingo: Everything you need to know about FFUF

FFUF: GitHub

GeeksForGeeks. ffuf – Fast Web Fuzzer Linux Tool Written in Go

Konko Maji. ffuf Writeup — a Tryhackme room

Kysymys i: nikto

NIKTO on havoittuvuuksien skanneri. Nikto suorittaa yli 6000 testiä verkkosivustoa vastaan. Se skanna palvelimien tietoturva-aukkoja ja väärät konfiguratiot.

Käynnistin sen vain -host parametrilla. Tuloksena nikto ilmoittanut löytäneensä vahan version Apache palvelimesta, sen havoittuvuuksia, phpMyAdmin ja phpinfo. Nikto myös selitti havaintojaan, mikä auttaa tulosten tulkinnassa.

Lähde:

Hacker Target. Nikto Website Scanner

Kysymys j: Pizza fantasia: jokin valitsemasi tiedustelutyökalu, esimerkiksi EyeWitness, wpscan, openvas, nucleus tai jokin muu.

Päätin kokeilla Nessus työkalua. Nessus on web sovellus. Se käyttää Nmapin kaltaisia tekniikoita haavoittuvuuksien etsimiseen ja raportoimiseen, jotka sitten esitetään mukavassa käyttöliittymässä.

Asensin Nessus ohjelman TryToHackMe sivustoilla olevien ohjeiden mukaan. Pitänyt ensin rekisteröityä ja saada aktivointikoodin (Essentials versio). Latasin ohjelmapaketin Nessus-10.1.2-ubuntu1110_amd64.deb Tenablen virallisilta sivuilta: https://www.tenable.com/downloads/nessus

Sitten avasin paketi ja käynnistin sovelluksen.

$ mkdir Nessus

$ cd Nesus

$ sudo dpkg -i Nessus-10.1.2-ubuntu1110_amd64.deb

$ sudo /bin/systemctl start nessusd.service

Sen jälkeen avasin sen selaimessa https://localhost:8834/ jossa viimeistelin asennusta ja konfiguraatiota. Asennusvelho pyytää aktivoida sovelluksen aktivointikoodilla.

Nessus ohjelman asennus kestänyt useita minuutteja. Asennus vaatii noin 5 GB vapaata tilaa kovalevyllä. Ensimmäinen asennusyritys Kali linux koneelle kaatui, koska siellä ei ollut tarpeeksi tilaa.

Lopulta sain sen asennettua. Sovellus pyytänyt syöttää verkkoavaruuden, minkä pitää skannata. Syötin Metasploitable 2 koneen IP-osoitteen. Skannaus tkei yhteensä 69 havaintoa, joista 7 oli kriittisiä ja 4 korkean tason havoittuvuuksia. Raportin skannauksesta voidaan exportoida XML muotoon tai tietokantaan. Nessus on lisännyt tuloksiin kriittisenä havoittuvuutena myös käyttöjärjestelmän loppunut tuki, mitä mikään muu käyttämäni skanneri ei tehnyt.

Nessus on tehokkain ja helppokäyttöisin skanneri mitä tähän asti olen nähnyt. Sillä on helppoa skannata suurempia verkkoja ja tulokset on helppoa käsitellä ja tulkita. Se sopii suuremille yrityksille, joiden verkkoissa on satoja koneita. Nessus Essentials lisenssi antaa skannata vain rajoitetun määrän IP-osoitteita (16)

 

Lähteet:

TryToHackMe. Nessus

Tenable. Video

Tenable Documentation. Create and Manage Scans

Nmap.org

Wireshark. Display Filters

Stack Exchange. Why do I need root privileges to send a raw packet from a UNIX machine?

StationX. Nathan House. Nmap Cheat Sheet

TechTarget. Address Resolution Protocol (ARP)

StackExchange: different behavior: “sudo nmap” vs just “nmap”?

TechDhee. How To Install Apache on Kali Linux

GeekUnitevsity. The reason flag

 

Tehtävä 5

h5 Script Kiddie

Task v: Lue artikkelit ja katso videot, tee kustakin muistiinpanot (muutama ranskalainen viiva per artikkeli/video). Tässä v-kohdassa ei tarvitse tehdä mitään kokeita koneella.

Vastaus:

  • Metasploit on tietoturvaprojekti, joka tarjoaa eksploiteja ja monia tiedusteluominaisuuksia, mitkä voi käyttää tunketumistestauksessa.
  • Metasploit on esitetty  YouTube-kanavаlla.
  • Metaspilot-ohjelmasta on kaksi versiota. Framework versio sopii kehittäjille ja tietoturvatutkijoille, koska se on ilmainen ja lähdekoodi on avoin. Pro-versiota käytetään ensisijaisesti ammattimaiseen, edistyneeseen ja laajaan levinneisyystestaukseen ja yritystietoturvaohjelmistoihin.
  • Metasploitissa käytetyt perustermit:
    • Exploit: On koodinpätkä, joka suoritettuna hyödyntää kohteen haavoittuvuutta.
    • Payload: On koodinpätkä, joka suoritetaan kohteessa onnistuneen hyödyntämisen jälkeen. Se määrittelee toimet, jotka haluamme suorittaa kohdejärjestelmässä.
    • Auxiliary: Ovat moduuleja, jotka tarjoavat lisätoimintoja, kuten skannauksen (scanning), sumennuksen (blurring), haistamisen (sniffing) ja paljon muuta.
    • Encoders: Käytetään moduulien hämärtämiseen (obscure), jotta suojamekanismi, kuten virustorjunta tai palomuuri, ei havaitse niitä.
    • Meterpreter: On hyötykuorma, joka käyttää muistissa olevia DLL-injektiovaiheita. Se tarjoaa erilaisia toimintoja, joita voimme suorittaa kohteessa.
  • Metasploit Wiki
  • Metasploit vastaa puhtaammasta poistumisesta vaarantuneista järjestelmistä, ts. ei riko testattavaa järjestelmää.
  • Skannaus: Nmap on yksi parhaista saatavilla olevista työkaluista. Nmapin tuottamat raportit voidaan helposti tuoda Metasploitiin. Metasploitissa on sisäänrakennetut Nmap-toiminnot.
  • DB: Tunkeutumistestauksen tulokset voi tallentaa automaattisesti tietokantaan sellaiseen kuin PostgreSQL. Tietokantojen käyttö Metasploitissa myös nopeuttaa hakua ja parantaa vasteaikaa. Komennolla workspace skannattujen järjestelmien tulokset voidaan jakaa siten, että tulokset eivät sekoituisi.
  • Penetraatiotesti Metasploit ohjelmalla:
    • Skannaus Nmap ohjelman avulla. Skannataan portteja, porteissa käynnissä olevien palveluiden versioita, käyttöjärjestelmän versiota, haavoittuvuuksia. Nmap parametrit löytyvät tästä linkistä.
    • Uhkien mallinnus:
      • Etsitään löytyykö valmista modulia haavoittuvuudelle search komennolla. Modulin Rank luokka esittää kuinka todennäköisesti moduli tulee toimimaan.
      • Ladataan apumoduuli use -komennolla
      • Konfiguroidaan apumoduli set -komennolla
      • Käynnitetään apumoduli run -komennolla
      • vulns komento lisää tiedot havoituvuudesta tietokantaan
    • Haavoittuvuusanalyysi: Etsitään tietoja havoittuvuudesta tietolähteistä kuten NVD ja muualta.
    • Hyödyntäminen ja pääsyn saaminen:
      • Ladataan exploit moduli use -komennolla
      • Katsotaan modulin parametrit show options -komennolla
      • Konfiguroidaan moduli set -komennolla (LHOST-parametria (oma IP) käytetään paluuyhteyttä varten)
      • Käytetään exploit modulia exploit -komennolla
      • Tarvittaessa vaihdetaan shell Meterpreter:ksi session –u komennolla
    • Post-exploitation kung fu:
      • Naamiodaan vaihtamaalla Meterpreter shell PID:tä ohjelmaksi joka ei herä epäilyjä.
      • Onnistuneen hyökkäyksen jälkeen käytetään post -moduuleja. (Pitää laittaa Meterpreter tomimaan taustalla background -komennolla)
      • Meterpreter arp shell-komento näyttää IP-avaruudet, joihin koneella on pääsy. Sen kautta voidaan hyökätä muihin koneisiin. (autoroute moduli)
      • On mahdollista vaarantaa järjestelmänvalvojan tili varastamalla token ja esiintyä domainin järjestelmänvalvojana käyttämällä Metasploit incognito -laajennusta.
      • Voidaan käyttää Domain Controller konetta käyttämällä Metasploit local_ps_exec -post modulia.
      • Voidaan ottaa taltteen kaikkien Active Directoryn käyttäjien salasanatiivisteet käyttämällä smart_hashdump -post modulia.
      • Metasploit-moduuleilla mimikatz tai kiwi voi ottaa taltteen järjestelmän käyttäjätunnukset koneen muistista.
    • Järjestelmällinen lähestymistapa tunkeutumistestaukseen on tärkeää. Kaikki löydöt on dokumentoitava, jotta niistä voidaan raportoida myöhemmin.

 

Lähteet:

Nipun Jaswal 2020: Mastering Metasploit

StationX:  Nmap Cheat Sheet

PenTest Magazine: Metasploit Cheat Sheet

 

Task a: Emmental. Asenna Metasploitable 3

Yritin asentaa Matasploitable 3 Rapid 7 GitHub repositorysta virtuaaliselle Kali linux distrolle joka pyörii VMWare Workstation 15 Pro hypervisorilla Windos 10 isäntäkoneella. Käytin GitHub reposta löytyneitä ohjeita, mutta asennus oli epäonnistunut. Uudessa Ubuntussa jolla Kali on tehty puuttunut osa Ruby Gem moduleita ja kuin sain niitä asennettua, ja yritin asentaa Vagrantin plugin vagrant-libvirt tuli virhe liittyen konflikttiin net-ssh kirjaston Gemfile.lock tiedostossa. Etsin ratkaisua useita tunteja, mutta lopulta luovutin ja asensin toisen VM:n Ubuntu 18.04.

Asensin Ubuntua ja allokoin koneelle 8GB RAM, 70GB HDD, 2x NIC yhden NAT asetuksilla ja toisen Host-only. Päivitin Ubuntun paketteja, asensin koneelle openssh-server ja käynnistin sen, jotta konelle pääsisi SSH-yhteydellä Windows isäntäkoneelta MobaXterm SSH-klientiä käyttäen.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install openssh-server
$ sudo systemctl enable ssh
$ sudo systemctl start ssh

Asensin myös net-tools koska sitä ei ole Ubuntussa oletuksena ja tarkistin koneen verkkoasetukset

$ sudo apt install net-tools
$ ifconfig -a

Koneen IP oli VMWaren virtuaaliverkon 192.168.142.0/24 avaruudessa.

Valitsin Ubuntu 18.04 koska opettajamme Tero Karvisen ohjeissa mainittiin, että asennus toimii Ubuntu 18.04 versiossa

$ mkdir metas/ && cd metas/
$ sudo apt-get -y install virtualbox vagrant curl

Lisäsin Vagrantfile nano editorilla.

$ nano Vagrantfile

## Vagrantfile
## http://terokarvinen.com/2018/install-metasploitable-3-vulnerable-target-computer
Vagrant.configure(“2”) do |config|
config.vm.box = “rapid7/metasploitable3-ub1404”
config.vm.network “forwarded_port”, guest: 80, host: 8080
end

Käynnistin Vagrant, jouduin painaamaan
$ vagrant up

Käynnistin Vagrant, jouduin painamaan Ctrl + C, koska tuli virheilmoitus autentikaatiosta, koska sessio yritettiin luoda SSH-avaimia käyttäen. Sen jälkeen avasin Ubuntu koneen selaimessa http://localhost:8080

Avasin VirtualBox ohjelman jolla pyörii virtuaalinen Metasploit 3 syöttämällä seuraavaa komentoa Ubuntu koneella:

$ virtulabox

Vaihdoin virtuaalisen Metasploit 3 koneen verkkoasetukset ja käynnitin sen uudelleen. Tähän pitänyt lukea miten se tehdään Vagrant Housekeeping sivustolta.

Uudelleenkäynnistyksen jälkeen Metasploit on saanut oman IP-osoitteen 192.168.142.138, joka näkyi myös isäntäkoneeltani. Avasin sieltä selaimessa http://192.168.142.138

Kokeilin kirjautua Metasploitable 3 koneelle SSH-yhteydellä, se toiminut kanssa. Eli kone on VMWaren virtuaaliverkossa ja koneelle pääse myös Kali linux virtuaalikoneelta joka on samassa verkossa ja jota meinaan hyökkäyksessä.

Sources:

Vagrant Housekeeping

Tero Karvinen: Install Metasploitable 3 – Vulnerable Target Computer

Rapid7 GitHub repository: https://github.com/rapid7/metasploitable3

 

Task b: Msf. Murtaudu Metasploitable 3 käyttämällä Metasploittia ‘sudo msfconsole’

Tämän tehtävän teen Kali linux virtuaalikoneelta, jolla on valmiiksi asennettu Metasploit ohjelma. Päätin aloittamaan skannamalla virtuaaliverkon osoitteet. Alotin sannamalla verkkoa iman porttisannausta komennolla:

$ nmap -v -sn 192.168.142.0/24

Käynnissä olevia koneita löytynyt osoitteista:

192.168.142.2 – VMWaren osoite

192.168.142.133 – Kali linux

192.168.142.137 – Ubuntu linux (Metasploitable 3 isäntä)

192.168.142.138 – Matasploitable 3

Seuraavaksi sannasin portteja:

 

Asensin Metasploit Framework komennolla:

$ sudo apt-get install metasploit-framework

Loin Metasploitin tietokannan:

$ sudo msfdb init

Käynnistin Metasploit 6 konsolin:

$ msfconsole

Loin uuden työtilan kannassa tätä harjoitusta varten

Skannasin verkkoa vielä kerran Metasploit konsolista, niin tulokset tallentuvat kantaan.

Tuloksesta näkee, että koneen OS on Ubuntu. Portilta 8080 löytyy Jetty palvelin ja sen versio, jolla löytyy havoittuvuus CVE-2019-10247. Kokeilin etsiä explotin tälle havoittuvuudelle.

msf6 > search cve:2019-10247
[-] No results from search

Kokeilen skannata SMB portti 445. Ensin katsotaan OS version.

msf6 > db_nmap -Pn -p445 –script smb-os-discovery 192.168.142.138.

Portilla 445 toimii Samba 4.3.11-Ubuntu, etsin havoittuvuuksia tälle vesiolle. Löysin sivuston, jossa havoittuvuudet on luoteltu. Kokelin etsiä exploitteja search komennolla.

Havoittuvuudelle CVE-2017-7494 löytynyt valmis exploit exploit/linux/samba/is_known_pipename

use linux/samba/is_known_pipename

set RHOSTS 192.168.142.138

set target 0

set payload payload/cmd/unix/interact

exploit

Kokeilin vaihtamaan parametreja, mutta en löytänyt sopivaa, joka avaisi takaoven. Aikaa meni noin 2 tuntia, joten jatkoin etsimään toista havoituvuutta.

 

Seuraavaksi päätin kokeilla ProFTPD portilla 21. Etsin serch proftp komennolla mitä kaikkia löytyy Matasploitissa tälle palvelulle.

ProFTPD:lle löytynyt useampi exploit, valitsen exploit/unix/ftp/proftpd_modcopy_exec

 

Tarkistin mitä payloadia löytyy tälle exploitille ja valitsin sopivan payload/cmd/unix/reverse_python

Tarkistin mitä parametreja pitää antaa exploitille ja syötin ne.

Käynistin exploit, mutta se  ei onnistunut luomaan yhteyttä. Virheilmoituksessa lukee, että kansioon ei voitu kirjoittaa mitään.

Asetin parametrin sitepath /var/www/html, mutta sekin ei onnistunut.

Exploit näyttänyt käynistäneen, mutta yhteyttä takaksin ei voitu luoda. Päätin tarkistaa palomuurin asetuksia Kali linux koneelta, koska jos portti johon exploit yrittää ottaa yhteyttä on kiinni, niin yhteyttä ei voi muodostaa. Palomuuri oli päällä. Otin sen pois päältä ja exploit on luonnut shell yhteyden onnistuneesti www-data käyttäjänä.

Huomaisn, että käyttämäni Metasploitin exploit jättää koneelle jälkejä. Kansioon /var/www/html ilmestynyt PHP-tiedostot, joita exploit oli tuonnut koneelle ja joita se käyttää. Näillä jäljellä hyökkäystä voidaan havaita. Hyökkäyksen jälkeen niitä olisi hyvää poistaa kohdekoneelta.

Task c: Rat. Demonstroi meterpreter:n käyttöä

Meterpreter on Metasploit-hyökkäyshyötykuorma, joka tarjoaa interaktiivisen kuoren, josta hyökkääjä voi tutkia kohdekonetta ja suorittaa koodia. Meterpreter otetaan käyttöön käyttämällä muistissa olevaa DLL-injektiota.

 

Jatkoin seuraavana päivänä, joten minun pitänyt tehdä kohdekoneen exploit uudestaan. Käynnistin Metaspoit ja syötin tavittavat parametrit, mutta exploit ei saanut muodostettu yhteyttä.

Virheilmoituksesta näkee, että expoit ei saanut toimitettua 220 Ok banneria takaksin. Ehkä portti 4444 Kalikonella, johon expoit yrittänyt luoda yhteyttä on joo varattu. Vaihdoi asetukset LPORT 4445:ksi. Se autoi, kohde kone on taas kaapattu.

Laitoin avoimen session pyörimään taustalla panamall CTRL + Z ja etsin Metasploitista serarch komennolla meterpreter ja linux

msf6 exploit(unix/ftp/proftpd_modcopy_exec) > search meterpreter linux

Hakutuloksia tuli paljon, mutta lupavilta näyttävät vain yksi post -alkuinen moduli post/multi/manage/shell_to_meterpreter. Sitä käytetään silloin kun yhteys kohdekoneeseen on joo luotu. Meterpreter Shell tarjoaa helpoimpia tapoja tehdä joitakin asioita vaarantuneessa koneessa

Valitsin meterpreterin shell komennolla use, asetin LPORT ja LHOST parametrit, asetin avoinna olevan session 1 ja käynnitin exploit. Meterpreter avasi toisen session kohdekoneen toiselle portille 56841. Komento whoami näytti, että shell on edelleen Kali koneella.

Hain meterpreter ja post yhdistelmällä moduleita. Hakutuloksia tuli paljon, päätin kokeilla post/multi/manage/autoroute Metasploitilla sessiota valitaan komennolla sessions ja antamalla session ID:tä, esimerkiksi sessions 2. Metrepreter auennut, mutta shell oli vielä Kali koneella. Valitsin autoroute modulin, mutta tuli ilmoitus SESSION may not be compatible with this module. Päätin kokeilla toisen modulin.

Tällä hetkellä on auki kaksi sessiota. Niiden jKäynnistin Meterpreter sessions 2 -komennolla valitsen Meterpreter sessiota aktiiviseksi. Meterspreterilla on omat komennot. Voi listata tiedostot ls komennolla, voi ladata tiedostot omalle konelle download komennolla. Latasin yhden Metasploitin payloadin tekemistä PHP-tiedostoista.

Tiedoston sisältö on yhden rivin koodipätkä. En ymmärrä miten se toimii.

tiedoston sisältöä voi katsoa cat -komennolla. Katsoin mitä eroa on PHP-tiedostoissa. Erona on portti numero Kali konella, josta hyökkäys tehtiin ja GET pyynnön merkkijono. Näkyy myös hyökkäjän IP-osoite, joten olisi hyvää poistaa tiedostot hyökkäyksen jälkeen peittäkseen jälkiä.

rm -komennolla voi poistaa tiedostoja. Kokeilin poistaa yhden Metasploitin tekemistä PHP-tiedostoista. Onnistui.

Meterpreter shellissa pystyy siirtymään kansista toiseen. Oikeushallinta kuitenkin säilynyt ja käyttäjä jolla Metasploit pääsi sisään kohdekonelle ei omaa tarvitavia oikeuksia ei voi käsitellä kaikkia tiedostoja ja kansioita. Pitää jotenkin korottaa oikeuksia.

upload komennolla voi ladata haitaohjelman ja käynnistää sitä execute komennolla. Jätin sen tekemättä, koska minulla ei ole mitään haitaohjelmia omalla Kali linux koneellani.

Meterpreter voi silti ajaa hyötykuorman kanssa, mutta katson sen toisella kerralla. Ymmärsin, mitä Meterpreter on, opin työskentelemään sen kanssa ja ymmärtämään hieman sen toimintaa.

 

Lähteet:

Secret Double Octopus: Meterpreter

Offensive security: Meterpreter basics

Offensive security: MSFconsole Core Commands Tutorial

Nipun Jaswal 2020: Mastering Metasploit

Binamra Pandey: [Metasploit]Upgrade Normal Shell To Meterpreter Shell

 

Homework 6

h6 Can of Worms

Task v: Read/watch and summarize

  • Felten et al 2015: Bitcoin and Cryptocurrency Technologies, videos Week 2 (about 1,5 hours). Requires free registration. If you find it easy to follow, you can also optionally look at weeks 3 and four
Centralization vs. Decentralization
  • Centralization is the concentration of control over an activity or organization under a single authority
  • Decentralization is not all-or-nothing, because аlmost no system is purely centralized or purely decentralized
  • Aspects of decentralization in Bitcoin
    • P2P network anyone can run Bitcoin node,
    • Bitcoin mining is open to everyone, but it requires quite large capital expenditures, which limits the entry threshold and thereby centralizes Mining in the hands of those who can afford these expenditures.
    • System updates. Everyone can create software, which is an aspect of decentralization. But only trusted developers decide about changes in the system, and thus have great power, which is an aspect of centralization.
Distributed Consensus
  • The key technical challenge of decentralized electronic cash is distributed consensus.
  • For decades, research has been conducted in the field of computer science on consensus protocols. Traditionally, the motivation for this was to increase the reliability of distributed systems.
  • When changes occur on one node, they must occur on all other nodes or none of them, because otherwise the state of the distributed database will be inconsistent.
  • Distributed consensus:
    • The protocol terminates and all correct nodes decide on the same value.
    • This value must have been proposed by some correct node
  • Bitcoin is a peer-to-peer network. When a transaction occurs, it is sent to all network participants.
  • For optimization, transactions are placed in blocks.
    • All nodes have a sequence of blocks of transitions they have reached consensus on.
    • Each node has a set of outstanding transactions that it has heard about. These are the transactions for which consensus has not yet happened.
  • Consensus is a difficult, because nodes can fail, be malicious, and network connectivity can be poor.
  • No notion of global time. Not all nodes can agree on the general order of events
  • Bitcoin consensus works better in practice then in theory
  • Because Bitcoin is a currency, it introduces the idea of incentives into the distributed consensus protocol.
  • Bitcoin goes away with the nation of a specific starting point and ending point for consensus. Consensus happens over long time scales (about 1 hour)
Consensus without Identity: the Block Chain
  • Bitcoin nodes have no identity because it is difficult in a P2P network, and pseudonymity is the goal of bitcoin.
  • Consensus algorithm (simplified):
    • New transactions are broadcast to all nodes
    • Each node collects new transactions into a block
    • In each round a random node gets to broadcast its block
    • Other nodes accept  the block only if all transactions in it are valid (unspent, valid signatures)
    • Nodes express their acceptance of the block by including its hash in the block they create
  • Honest nodes will extend the largest valid branch
  • If a transaction has received 6 confirmations, then the probability that another transaction of the same coin will be confirmed by the majority of nodes will decrease exponentially.
Incentives and Proof of Work
  • The Bitcoin network rewards nodes that create blocks to encourage them to behave honestly.
  • There are two ways to get a reward. The first one  is to create a new block, which in the long run will be confirmed by the majority of nodes. The second is the transaction fee, which is purely voluntary, like a tip.
  • Initially, the amount of remuneration for the creation of the block was 50 BTC, every 4 years it is halved. At the time of writing this article, it is now 6.25 BC. The maximum number of bitcoins that can be created is 21 million.
  • The idea of mining is to find a nonce number, the hash of which, together with the hash of the previous block and the sum of all transactions, would be a very small number starting with a certain number of zeros, known as a target. Every two weeks, the complexity of the target is recalculated so that it takes about 10 minutes to create one block.
  • Nonce number should be published as part of the block so that other miners can verify that the necessary calculations have been performed.
Putting It All Together
  • Mining costs are the costs of equipment and electricity consumed during the mining process
  • Any user can create any number of identies.
  • Security comes from the blockchain and the consensus protocol
  • The more blocks were found after the block where the transaction was contained, the more confidence that the transaction became part of the consensus chain.
  • Miners with large computing power resources are more likely to create a new block

Source: Felten et al 2015: Bitcoin and Cryptocurrency Technologies

 

Task a: Can of worms.

Run some malware in https://any.run web interface. What malware was that? How did it work? Take some screenshots, and explain what we see. Do you recognize any techniques or tactics? What did you learn? Do not download any malware samples to your own computer.

Answer:

Any.Run is an interactive online malware analysis tool. I registered on the service and after confirmation by email, signed into the website.

After a short tour and reading frequently asked questions, I realized that on this service you can check suspicious files and sites for malware. In the free plan, the check can only be performed on Windows 7 32 bit, which is a little sad, because support for Windows 7 ended on January 14, 2020.

To check files and sites on other versions of Windows, you need to buy a subscription, which costs about $89 for Searcher plan and $249 for Hunter plan.

Let’s run some malware sent by other users. By clicking on some country on the dashboard we can see the list of public submissions made by users from this country.

I choose the task: https://app.any.run/tasks/9322a875-a7c9-4f71-881c-fdc45d4a04f1 in which malicious activity was detected. I checked the text report on this task. It looks like the suspicious link redirects the session to some other website.

When I started the task, a window opened where a browser with a suspicious link opened on a Windows 7 computer. The link redirected the session from the Youtube site to the MediaFire file sharing site with a link to download the file. I downloaded the archived file, unzipped it and ran the executable file. Nothing happened, the program didn’t start, or so it seemed to me. In fact, the malicious code launched the modified program code of the original program.

On the Mitre Attack Matrix tab, you can see used tactics, techniques and events.

The malicious code used, among other things, the Browser extensions technique from the Persistence tactic. Malware changed Chrome browser extensions by adding two files verified_contents.json and  computed_hashes.json

I found out that there is an Any.Run resource where you can check suspicious files and links for malware. I also realized that if nothing happens on the screen when the executable file is launched, it does not mean that nothing happens in the background in the computer processes.

Source:  Any.Run

Task b: Reference implementation.

Ever cop^H^H^Hlearned from StackOverflow? Pick a StackExchange site related to the course, sort questions by score, and briefly explain one question and answer. https://stackexchange.com/sites

I tried to find the answer to the question on the StackExchange website what is the computed_hashes.json file and where it is used.

In the list of links there was a link to the StackOverflow website, which I opened.

“It is to ensure the integrity of the files, to make sure they were not modified. ”
Iván Nokonoko  Jan 31, 2018 at 12:49

The answer to this question was very convincing and concise. I believe that the installed extension in the previous task, installed the extension that was changed, and the file writed by the malware should hide it, indicating that the integrity was not violated.

I also tried to find a bitcoin site on my computer and filter it by the highest score.

 

Sorces:

StackExchange

StackOverflow

Homework 5

h5 BitCoin

Task v: Read/watch and summarize

Summary

  • Satoshi Nakamoto’s paper presents a theory of an electronic payment system based on cryptographic proof rather than trust, allowing any two willing parties to make transactions directly with each other without the need for a trusted third party such as a central bank, which is the currency’s issuer.
  • A solution to the double waste problem is presented, based on a distributed peer-to-peer timestamp server, which confirms the chronological order of transactions with its computational proof.
  • The system is safe as long as there is more computing power under the combined control of its honest participants than under the control of a group of attackers acting together.
  • Participants need to openly publish transactions, as well as be able to come to an agreement on a single order of their sequence.
  • The transaction contains a hash of the previous transaction signed by the previous owner of the coin and the public key of the current owner. It is signed with the secret key of the current owner of the coin, which can be verified using his public key.

  • Transactions are collected in blocks. Transaction approval is the moment when transactions merge in the found block. One block includes one confirmation, and when it is confirmed by the majority of network participants, the transaction becomes fully confirmed.
  • Proof of work: In blockchain mining, miners validate transactions by solving a difficult mathematical puzzle called proof of work. To do that, the primary objective of the miner is to determine the nonce value, and that nonce value is the mathematical puzzle that miners must solve in order to generate a hash starting with a certain number of zero bits. The creator of the block who found a nonce receives a reward.
  • The entire chain of blocks can be tracked using Hash pointers to the previous block
  • Scrooge coin, unlike Goofy coin, solves the problem of double spending, but does not solve the problem of a centralized currency issuer.

 

Sources:

Nakamoto, Satoshi 2008: Bitcoin: A Peer-to-Peer Electronic Cash System

Felten et al 2015: Bitcoin and Cryptocurrency Technologies

https://www.simplilearn.com/bitcoin-mining-explained-article

 

Task a:  Value of bit money. How much is one BitCoin (BTC) worth now? Using historical BTC course, show that you could have lost a lot of money investing in BTC. Also show that you could have won a lot of money with BTC.

The value of a currency is a measure of the demand for it and its ability to stimulate trade and business inside and outside the economy. Thus, Bitcoin is not a classic currency, because it is almost not used in retail. Bitcoin is more like gold, its quantity is limited, and its value varies in proportion to the demand for it. Bitcoin demonstrates some of the attributes of a currency, but its main source of value lies in limited supply and growing demand. The Bitcoin price is determined by a complex combination of factors that include production costs, competition, and regulatory developments.

The vast majority of institutional investors are still wary of putting their money into the cryptocurrencies, resulting in less liquidity and more volatility for its ecosystem. However, the rapid growth of the exchange rate attracts small investors and individuals to the market, who do not always have sufficient knowledge to successfully trade in this market. It is quite easy to lose money in the cryptocurrency market due to their high volatility. Thousands of investors jumped only recently when the Bitcoin price and hype reached unprecedented heights.

Investment company 21Shares conducted a study. Based on the timestamps, 21Shares was able to aggregate the base cost for each registered bitcoin transaction. According to the results of the study, as of February 8, 2022, more than half of bitcoin investors are at a loss.

 

Binance. BTC/USD price 4/2021 – 4/2022.

As can be seen from the graph of bitcoin price changes over the past year, the bitcoin exchange rate is very volatile. On the day of writing the article, the bitcoin exchange rate has fallen by 8% over the past 24 hours. Investors who bought an asset at the peak of popularity lost up to half of their investments, while investors who entered the market a long time ago, when the exchange rate was lower, won.

 

Sources:

Investopedia. Why Do Bitcoins Have Value?

Investopedia. What Determines the Price of 1 Bitcoin?

Money. More Than Half of Bitcoin Investors Are in the Red, Study Says

Binace

 

Task b: Is it legal to own BitCoin in Finland? Why do you think so?

“It is legal in Finland to buy, sell and use cryptocurrency. On October 4, 2018 the Government of Finland released the Government Proposal 167/2018 (“HE 167/2018”) that proposes to regulate cryptocurrency providers. The Act on Virtual Currency Providers went into effect on May 1, 2019.” (Freeman law)

I believe that if this phenomenon cannot be stopped, then it should be enclosed in the legal framework of the law, which was done in Finland with the adoption of this law.

Sources:

Freeman law: Finland and Cryptocurrency

Task c: What’s a block chain? Give a simple but detailed explanation. (Feel free to use the most narrow and simple definition of blockchain – no need to consider a whole cryptocurrency).

The blockchain contains blocks, and blocks contain transactions.

A transaction in the blockchain is a record of a change in the state of assets when someone also transfers an asset to someone else.

A transaction block is a special structure for recording a group of transactions. In the bitcoin blockchain, each block holds about 3,000 transactions. In addition to transactions, there is a header in the block. It records the hash of all transactions, the hash of the previous block, the time of block creation and other service information.

Several blocks connected in a sequence form a chain. In it you can find the entire history of asset transfers from hand to hand. The block cannot be deleted or changed because the hash of the previous block is written in the header. Thus, the chain becomes consistent and unbreakable. By changing even one transaction, the hashes of all subsequent blocks along the chain will change and such a version of the blockchain will be considered invalid.

Sources:

https://maff.io/block_chain_transaction/

Task d: Not BitCoin. Give examples of some AltCoins, crypto currencies compiting with BitCoin. For each AltCoin: how does it differ, what’s it’s claim for fame?

Altcoin or alternative coin is any other cryptocurrency other than Bitcoin for example Ethereum, Ripple, Litecoin, Dogecoin

Ether (ETH) is the currency of the Ethereum system. In the Ethereum system, where blockchain technology is used to create applications that go beyond the simple use of digital currency.

Ethereum enables the deployment of smart contracts and decentralized applications to be built and run without any downtime, fraud, control, or interference from a third party. Ethereum comes complete with its own programming language that runs on a blockchain, enabling developers to build and run distributed applications.

Key differences from Bitcoin

  • Transactions on the Ethereum network may contain executable code, while data affixed to Bitcoin network transactions are generally only for keeping notes.
  • Differences in the speed of creating building blocks and thus in the speed of transactions. An ethereum transaction is confirmed in seconds, compared to minutes for bitcoin.
  • Bitcoin uses the SHA-256 algorithm while Ethereum uses the Ethash algorithm.
  • “Bitcoin and Ethereum networks are different with respect to their overall aims. While bitcoin was created as an alternative to national currencies and thus aspires to be a medium of exchange and a store of value, Ethereum was intended as a platform to facilitate immutable, programmatic contracts and applications via its own currency. ” (Investopedia)

Sources:

Investopedia. Bitcoin vs. Ethereum: What’s the Difference?

Homework 4

h4 The Dark Web and the TOR Browser

Task x: Read and summarize: Shavers & Bair 2016: Hiding Behind the Keyboard: The Tor Browser

 

The Tor Browser is a chapter in “Hiding Behind the Keyboard. Uncovering Covert Communication Methods with Forensic Analysis” written by Brett Shavers and John Bair. The chapter describes the principles of the The Onion Router network and methods of investigating crimes committed using the TOR browser.

TOR browser is a browser based on Mozilla Firefox, which allows users to anonymously use Internet resources. The idea of onion routing is that a request to an Internet resource comes from a client through a chain of relays, also known as a TOR Circuit. There are Entry/Guard, Middle and Exit relays in a TOR Circuit.

Each relay only knows the previous and next traffic recipient, so the middle relay does not know the sender and the final recipient. Internet traffic is encrypted as many times as there are relays in the circuit and only the traffic between the Exit relay and the end resource is not encrypted.

Tor relays are run by volunteers around the world and the IP addresses of the relays can be found on the website of the Tor project Metrics. In addition, there are Bridges whose IP addresses are not published. They can be used in countries where public relays can be blocked by the government, such as China. At the time of writing this article, there were about 7000 Relays and 2000 Bridges around the world.

Installing and using the Tor browser is very simple. It is enough to download the installation package from the page of the Tor project and install it on the local machine. After that, it is enough to use the default browser settings.

The Tor browser does not create artifacts on the local machine, but traces of using the Tor network can be found on the computer. It is more secure to use the TOR browser from an operating system from a USB or DVD media that does not require installation, for example, Tails, which has a pre-installed Tor. Alternatively, you can configure the Linux bootloader (GRUB2) to bypass the operating system and boot from the ISO image. Black Hat also recommends using a good VPN with Tor browser. I downloaded and ran Tails in a VMWare virtual machine from an ISO image.

Since the Tor browser uses the Mozilla Firefox engine, the vulnerabilities in it also extend to the Tor browser. So the FBI was able to reach the distributors of child pornography Freedom Hosting using a vulnerability CVE-2013-1690 in Firefox ESR 17.x before 17.0.7

Hidden services on the tor network are also known as the Dark Web. These services provide email or web hosting services. Unlike conventional Internet resources in the TOR network, hidden services do not use Exit relays, and therefore provide end-to-end encryption of Internet traffic between the user and the hidden service. Hidden services are not indexed by search engines and are therefore almost invisible to the Internet. Hidden services use a top – level domain .onion and have the form juhanurmihxlp77nkq76byazcldy2hlmovfu2epvl5ankdibsot4csyd.onion/i2p/ (AHMIA i2p network search). Many hidden services sell illegal goods such as drugs, weapons, credit card numbers, child porn and much more.

Source: Shavers & Bair 2016: Hiding Behind the Keyboard.

Task a: Install TOR browser and access TOR network (.onion addresses). (Explain in detail how you installed it, and how you got access to TOR).

I am using Kali linux distribution release 2022.1 on the VMWare Workstation 15 Pro hypervisor. I found instructions for installing the TOR browser for Kali linux and installed the TOR Browser using these instructions

 

$ sudo apt update

$ sudo apt install -y tor torbrowser-launcher

 

Source: https://www.kali.org/docs/tools/tor/

After that, TOR Browser and TOR Browser Launcher appeared in the main menu as installed programs

 

Task b: Browse TOR network, find, take screenshots and comment

  • search engine for onion sites
  • marketplace
  • fraud
  • forum

Since hidden services are not indexed by conventional search engines, then to search in the domain .onion need to use special search engines. Unfortunately, hidden services often change URL addresses and even close. Links to search engines can be found on their websites on the clearnet. The stable search engines in the Tor network are AHMIA, TORCH.

 

There are also lists of links on the Tor network, such as a The Hidden Wiki page and OnionLinks.

 

In the vastness of the Tor network there are marketplaces where you can buy illegal goods such as drugs, weapons, stolen credit card numbers and much more.

 

From what I understand, some of them provide escrow payment services. So the buyer can be sure that the seller will not scam him.

 

One of the most popular types of fraud that I have encountered on the Tor network is carding. Carding is a whole underground industry in which fraud is committed with the victims’ credit cards. In carding, the roles are strictly divided between the participants, someone steals credit card data, someone uses them by buying and ordering goods online, someone sells the goods received in this way for real money. If you are interested in carding and credit card security, read my article.

 

There are communication forums on the hidden services of the Tor network. Many of them require registration to access them, which I don’t want to do. Therefore, I found one forum in which registration is not needed to read the messages, and it also turned out to be on the topic of carding.

 

While I was studying the possibilities of the Tor network, I noticed that the Tor makes it possible to circumvent the prohibitions on viewing Internet resources in a particular country. For example, at the time of writing this article, many Russian resources are blocked for viewing on the territory of the European Union and in particular Finland. Using some Tor circuits you with an exit node in a country where there is no ban, makes it possible to view these resources. For example, the website of the news agency Russia Today is blocked for viewing in Finland, but it can be viewed on the Tor network.

 

If take a look at circuit, there can see all the relays. Guard or Entry relay in the Netherlands, Middle relay in France and Exit relay in Germany, where from rt.com site is not blocked.

 

Task c: Find an example where anonymity of TOR user was compromized. How was it done? Who did it? Could the deanonymization be replicated?

One example where anonymity has been compromised is the FBI’s operation to infect Freedom House servers with an exploit that exploited a vulnerability CVE-2013-1690 in Mozilla, on which the Tor browser is built. FBI agents managed to configure the site server so that it infects users’ computers, where malicious code was run and searched for the victim’s MAC address and hostname and sent them back as an HTTP web request to the FBI server.

I believe that at the moment this particular vulnerability cannot be repeated with the new version of the Tor browser, where this vulnerability has been eliminated. However, vulnerabilities in programs are constantly being found, and I do not exclude the possibility of using other vulnerabilities for deanonymization of Tor network users.

 

Sources:

https://resources.infosecinstitute.com/topic/fbi-tor-exploit/

https://siliconangle.com/2013/08/06/darknet-freedom-hosting-sites-shutdown-led-by-fbi-exploit-use-against-tor-network/

 

Task d: What other pseudonymous/anonymous networks are there? What’s their killer feature? How are they different from TOR?

Other anonymous networks are I2P(Invisible Internet Project) and Freenet.

I2P

As stated on the I2P website it is a fully encrypted private network layer that has been developed with privacy and security by design in order to provide protection for activity, location and identity. I2P uses encryption to form various properties of the tunnels used and the messages supported over them. I2P tunnels use NTCP2 and SSU transports. The network is made up of peers (“routers”) and unidirectional inbound and outbound virtual tunnels. The software provides a router that connects to the network. Routers communicate with each other using protocols built on existing transport mechanisms (TCP, UDP, etc), passing messages. I2P provides its own unique DNS. The I2P network is almost completely decentralized, with the exception of the so-called Reseed servers, through which you first join the network.

Comparisons of I2P and Tor can be found on the project’s website. Here are some advantages of I2P:

  • Hidden services are much faster than in Tor
  • Fully distributed and self organizing
  • Peers are selected by continuously profiling and ranking performance, rather than trusting claimed capacity
  • Peer-to-peer friendly
  • Packet switched instead of circuit switched
  • Both TCP and UDP transports
  • Java, not C

Freenet

Freenet is a peer-to-peer network designed for decentralized distributed storage of data without the possibility of censorship, created to provide users with electronic freedom of speech by making it impossible to delete or block files.

Freenet can be thought of as a large storage device. When you save a file in it, you get a key that you can use to retrieve the file. When you insert a key into Freenet, it will return the corresponding file (if it is on the system). Storage space is shared among all connected nodes in Freenet.

Freenet is a peer-to-peer network that is decentralized and anonymous. The nodes you connect to know only their nearest neighbors and do not know how the network as a whole works.

 

Sources:

https://www.eecs.yorku.ca/course_archive/2019-20/F/4482/Team9_AnonymousNetworks.pdf

https://geti2p.net/en/

https://freenetproject.org/

 

Task e: In your own words, how does anonymity work in TOR? (e.g. how does it use: public keys, encryption, what algorithms?)

Communication between relays in circuit occurs using AES, asymmetric key cryptography. The key is agreed using Diffie-Hellman. The user encrypts Internet traffic using the keys received from all relays in the circuit. It turns out an onion from layers of encryption, where each layer can only open the next relay in the circuit. Upon receiving the message, the relay decrypts its layer and forwards the message to the next relay. Thus, the request reaches the existential encrypted. The information is encrypted back by each relay and the user receives back the onion, which he encrypts.

Private and public keys, asymmetric encryption are used to publish hidden services. You can read more about it here.

 

Sources:

How Does Tor Really Work? The Definitive Visual Guide (2020)

How do onion addresses exactly work?

Task f: What kind of the threat models could TOR fit?

There is an attack in which the attacker tries to control both ends of the chain, called the Sylbil Attack. Named after the main character in Flora Rheta Schreiber’s book Sybil. Sybil attacks are not theoretical. In 2014 researchers at Carnegie Mellon University appeared to successfully carry out a Sybil Attack against the real-life Tor network.

Jansen and others. described an attack in which they DDOS out of the nodes. By degrading the network (removing exit nodes), the attacker increases the chance of getting an exit node.

Some applications, under Tor, reveal your true IP address. One such application is BitTorrent.

Usually, most Tor users get caught in crimes because of insufficient OpSec, and not because of security problems with Tor.

 

Source: https://skerritt.blog/how-does-tor-really-work/#attacks-on-tor-

 

Homework 3

h3 Public key encryption and PGP

Task a: Read and summarize (with 1-5 bullet points for each heading)

Schneier 2015: Applied Cryptography Chapter 1: Foundations

TERMINOLOGY

  • “A cryptographic algorithm, also called a cipher, is the mathematical function used for encryption and decryption. (Generally, there are two related functions: one for encryption and the other for decryption.)” (Schneier 2015)
  • The difference between symmetric and asymmetric encryption is that symmetric encryption uses the same key for both encryption and decryption, while asymmetric encryption uses two different keys for both procedures.

  • “Cryptanalysis is the science of recovering the plaintext of a message without access to the key. Successful cryptanalysis may recover the plaintext or the key.” (Schneier 2015) “An attempted cryptanalysis is called an attack.” (Schneier 2015)
  • A closed encryption algorithm is not a guarantee that it is reliable. The best encryption algorithms we have are the ones that have been made public, because they have been attacked by the world’s best cryptographers for years, and are still unbreakable.
  • “An algorithm is unconditionally secure if, no matter how much ciphertext a cryptanalyst has, there is not enough information to recover the plaintext.” (Schneier 2015)
  • “Pronouncing an algorithm secure simply because it is infeasible to break, given current technology, is dicey at best. Good cryptosystems are designed to be infeasible to break with the computing power that is expected to evolve many years in the future.” (Schneier 2015)

STEGANOGRAPHY

  • “Steganography serves to hide secret messages in other messages, such that the secret’s very existence is concealed. Generally the sender writes an innocuous message and then conceals a secret message on the same piece of paper.” (Schneier 2015)

SUBSTITUTION CIPHERS AND TRANSPOSITION CIPHERS

  • “Different cryptographic algorithms either substituted characters for one another or transposed characters with one another. The better algorithms did both, many times each.” (Schneier 2015)
  • “These days in computer era, algorithms work on bits instead of characters. This is actually just a change in the alphabet size: from 26 elements to two elements. Most good cryptographic algorithms still combine elements of substitution and transposition.” (Schneier 2015)
  • “A substitution cipher is one in which each character in the plaintext is substituted for another character in the ciphertext. The receiver inverts the substitution on the ciphertext to recover the plaintext.” (Schneier 2015)
  • “In a transposition cipher the plaintext remains the same, but the order of characters is shuffled around.”  (Schneier 2015)

SIMPLE XOR

  • “XOR is exclusive-or operation: ‘^’ in C or ⊕ in mathematical notation. It’s a standard operation on bits:
    • 0 ⊕ 0 = 0
    • 0 ⊕ 1 = 1
    • 1 ⊕ 0 = 1
    • 1 ⊕ 1 = 0    ” (Schneier 2015)
  • “XOR is a symmetric algorithm. The plaintext is being XORed with a keyword to generate the ciphertext. Since XORing the same value twice restores the original, encryption and decryption use exactly the same program:Р ⊕ К = С
    С ⊕ К = Р ” (Schneier 2015)
  • Simple XOR is a very low security encryption method.

ONE-TIME PADS

  • “In one-time pad each key letter is used exactly once, for only one message. The sender encrypts the message and then destroys the used pages of the pad or used section of the tape. The receiver has an identical pad and uses each key on the pad, in turn, to decrypt each letter of the ciphertext.” (Schneier 2015)
  • “Since every plaintext message is equally possible, there is no way for the cryptanalyst to determine which plaintext message is the correct one. A random key sequence added to a nonrandom plaintext message produces a completely random ciphertext message and no amount of computing power can change that.” (Schneier 2015)
  • “Key letters in one-time pad have to be generated randomly. Any attacks against this scheme will be against the method used to generate the key letters.” (Schneier 2015)
  • “Messages encrypted using one-time pads are still secure today and will remain that way forever. It doesn’t matter how long the supercomputers work on the problem.” (Schneier 2015)

COMPUTER ALGORITHMS

  • Three of the most common cryptographic algorithms are:
    • DES (Data Encryption Standard)
    • RSA (named for its creators—Rivest, Shamir, and Adleman)
    • DSA (Digital Signature Algorithm, used as part of the Digital Signature Standard)

LARGE NUMBERS

 

Source:

Bruce Schneier 2015: Applied Cryptography: Protocols, Algorithms and Source Code in C

 

Task b: Give two examples of public key cryptography (other than PGP). Explain how public keys are used here.

Public key cryptography serves both to authenticate a message and to ensure its confidentiality. How does it work? Well, the most commonly used use case for public key cryptography is network traffic using the HTTPS protocol encrypted with an SSL/TLS certificate.

 

The SSL certificate contains a public key that a browser downloads automatically when a user visits a website that uses the HTTPS protocol. Once the certificate is obtained, all traffic between the browser and the website will be encrypted using the public key from that website’s SSL certificate. The key pair is created by the owner of the website, and only the owner of the private key can decrypt the message encrypted with the public key.

 

But how can we be sure that the site certificate is a real certificate published by the site owner? Well, for this we can ask someone whom everyone trusts to certify the authenticity of the certificate of their digital signature. In a digital signature, asymmetric encryption works differently. A message, or in this case a certificate, signed with the Certificate Authority’s private key can be verified by anyone who knows the public key of the CA. The most commonly used root CA certificates end up in a web browser when you install or update your browser.

 

A certificate can be signed with multiple digital signatures. In this chain, the trusted issuer CA is always at the root level of the chain. For example, the Google.com website is digitally signed with a GTS CA 1C3 certificate signed by a GTS Root R1 certificate signed by the trusted provider GlobalSign Root CA – R1. All certificates in this chain are valid, so we can be sure that encrypted traffic sent to Google.com will only be decrypted by the owner of Google.com’s private key.

 

 

Task c: Encrypt and sign a message. Then decrypt and verify it. Use PGP to encrypt and sign messages.

I am using Kali linux distribution on the VMWare Workstation 15 Pro hypervisor. PGP comes pre-installed with Kali Linux, so I needed to read the pgp help to learn the command syntax.

$ gpg –help
gpg (GnuPG) 2.2.27
libgcrypt 1.9.4
Copyright (C) 2021 Free Software Foundation, Inc.
License GNU GPL-3.0-or-later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /home/kali/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

Syntax: gpg [options] [files]
Sign, check, encrypt or decrypt
Default operation depends on the input data

Commands:

 

In order to encrypt something, I needed to first generate a key pair using gpg command with option –gen-key . The wizard asked for my real name and email address.

$ gpg –gen-key
gpg (GnuPG) 2.2.27; Copyright (C) 2021 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Note: Use “gpg –full-generate-key” for a full featured key generation dialog.

GnuPG needs to construct a user ID to identify your key.

Real name: Aleksandr Pantsesnyi
You selected this USER-ID:
“Aleksandr Pantsesnyi <aleksandr.pantsesnyi@myy.haaga-helia.fi>”

Change (N)ame, (E)mail, or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.

Then I had to enter a passphrase.

I listed all existing keys using gpg –list-keys command

I created a test file using the nano editor

$ nano test-file.txt

After typing some text in the editor, I saved it with the Ctrl+X hotkeys, confirmed that I’m sure using the letter Y, and enter. After that, using the cat command, I checked the contents of the file.

Encryption

I then encrypted the test file using the -r (recipient) option and the –encrypt option with the filename. GPG has created a new file with a .gpg extension at the end of the name. This is an encrypted file whose content is encrypted and cannot be read by a human in the cat command.

Decryption

I then decrypted the encrypted file using gpg with the -d option and the filename. GPG asked me to enter the passphrase for the private key, after which the text of the file appeared on the screen in text format.

Signing

I signed the file using gpg with the –sign option and the filename. GPG created a new .gpg file that looked larger than just the encrypted file.

I checked the size of both files using the du command with the -b (bytes) flag. Adding the signature increased the file size by several hundred bytes.

Verifying

Using gpg with the –verify option and a filename, I got the file is really signed by me today using an RSA key, and the signature is good.

 

In the case of asymmetric encryption and digital signature, the same pair of public and private keys was used. In the case of encryption, it was done with a public key and decryption with a private key. In the case of a signature, a private key was used and the authenticity of the signature was verified with a public key.

 

Source: https://linuxhint.com/encrypt-decrypt-with-pgp/

 

Task f: Voluntary, programmers only: Cryptopals. Solve Set 1: Challenges 1-3. I highly recommend Cryptopals for learning to break cryptography.

Challenge 1: Convert hex to base64

I chose the Python language and Jupyter notebooks. After some googling, I figured out that I need to use the base64 library to accomplish this task. Using the b64encode method, I encoded and decoded a bytes string extracted from the HEX string. Then, using the b64decode method, I decoded the result back into a HEX string and compared that the decoded result equals the original HEX string.

Challenge 2: Fixed XOR

So, I had to write a simple function using Python language and Jupyter notebook. The function takes two arguments and returns the result as a byte string. Because the function must take two buffers of the same length, I added an assertion to compare the string lengths. Then, using a for loop, the function goes through each pair of bytes from both inputs and XORs that pair. The result of each XOR will be added to the result array using the append function.

Because the input strings are in the form of a HEX string, I had to first convert them to a byte type. I then called the function and gave the input strings as arguments. The result is printed as byte string and as HEX string also.

Challenge 3: Single-byte XOR cipher

In this task, I needed to find one character with a length of one byte. This means that I had to create a FOR loop in which I would iterate over all 256 options that can take a byte. On each iteration, I XORed the input string by byte value. So, I had 256 output options, from which I had to extract the best option in human-readable English. Typically, text is written using mostly lowercase letters and spaces between words. So the range of lowercase ASCII letters is 97-122, and the space character is 32. I created a list with all of these values, and on each iteration I compared the results for the highest match against the values in that list. The function returns a list of results that contains three values: the best match key, the most English letters, and the best match plain text.

I then passed a HEX encoded string to the variable and called a function that passed that variable as an argument. The returned result has been printed below.

Sources:

https://cedricvanrompay.gitlab.io/cryptopals/challenges/01-to-08.html

ASCII table : https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html

Homework 2

h2 hashes

Read and summarize

Santos et al 2017: Security Penetration Testing – The Art of Hacking Series LiveLessons: Lesson 6: Hacking User Credentials

Password best practices:

  • Strong long passwords
  • Unique password for each system
  • Multi-factor authentication
  • Disable default passwords
  • Using a VPN on Public Networks

 

How do we do better with passwords:

  • Hashing algorithms are not enough
  • Use salt on your hash
  • Create strong passwords every where
  • Use two factor authentication
  • Use certificate based authentication
  • Better randomness

 

Brute Force tools

Source:

Security Penetration Testing The Art of Hacking Series LiveLessons

By Omar Santos, Jon Sternstein, Ron Taylor, Chris McCoy

Hashcat

I am using Kali linux distribution on the VMWare Workstation 15 Pro hypervisor. Hashcat comes pre-installed with Kali Linux, so I needed to read the hashcat help to learn the command syntax.

$ hashcat –help
hashcat (v6.2.5) starting in help mode

Usage: hashcat [options]… hash|hashfile|hccapxfile [dictionary|mask|directory]…
I tried running hashcat in Benchmarking mode using the -b option. This failed due to insufficient memory allocated to the virtual machine.

After I allocated 8 GB of RAM to the virtual machine, hashcat started working in Benchmarking mode. But the speed was low, and I decided to increase the number of dedicated processor cores for the virtual machine. After that hashcat Benchmarking test was done in 2 minutes.

 

Crack the hash

The first task is to crack hash: 21232f297a57a5a743894a0e4a801fc3

So, I had to specify the hash type for hashcat. Using the Hash Analyzer service, I got that the type of this hash is MD5 or MD4. The hash type will be 0 or 900. First I will try MD5 using the -m 0 option.

Hash Aalyzer service: https://www.tunnelsup.com/hash-analyzer/

 

Because I was trying to crack one hash, I added it to the command as is, without putting it in a file first.

$ hashcat -m 0 -a 0 -o hashcat-output.txt 21232f297a57a5a743894a0e4a801fc3 /usr/share/wordlists/rockyou.txt

21232f297a57a5a743894a0e4a801fc3:admin

 

I knew that the password length is 5 symbols. I tried to crack it using mask option -a 3 and mask ?1?1?1?1?1

$ hashcat -m 0 -a 3 –show 21232f297a57a5a743894a0e4a801fc3 ?1?1?1?1?1
21232f297a57a5a743894a0e4a801fc3:admin

 

But what if the length of the password is unknown? In this case, you can use a length range and the -i increment option with minimum and maximum values.

$ hashcat -m 0 -a 3 –show -i –increment-min=3 –increment-max=10 21232f297a57a5a743894a0e4a801fc3
21232f297a57a5a743894a0e4a801fc3:admin

 

Crack Windows NTLM hash

Next task is to Crack this Windows NTLM hash: f2477a144dff4f216ab81f2ac3e3207d

I used password dictionary and output file windows-hash.txt

$ hashcat -m 1000 -a 0 -o windows-hash.txt f2477a144dff4f216ab81f2ac3e3207d /usr/share/wordlists/rockyou.txt

$ cat windows-hash.txt
f2477a144dff4f216ab81f2ac3e3207d:monkey

 

I tried to use mask with increment option

$ hashcat -m 1000 -a 3 –show -i –increment-min=3 –increment-max=10 f2477a144dff4f216ab81f2ac3e3207d
f2477a144dff4f216ab81f2ac3e3207d:monkey

 

Try cracking this hash and comment on your hash rate

Try cracking this hash and comment on your hash rate $2y$18$axMtQ4N8j/NQVItQJed9uORfsUK667RAWfycwFMtDBD6zAo1Se2eu (Update: Crack this -> Try cracking this. I’m interested in your comments on the hash rate, no need to get the password).

Well, for that, I needed to understand what hash rate means. I found the definition of the term:

“Hashrate is a measure of the computational power per second used when mining. More simply, it is the speed of mining. It is measured in units of hash/second, meaning how many calculations per second can be performed.”

Source: https://bitflyer.com/en-us/s/glossary/hashrate

Hash Analyzer gave me an example of hashes. It looked like a BCRYPT hash

I had added hash to the file bcrypt.txt and checked it using hashid tool

$ hashid -m bcypt.txt
–File ‘bcypt.txt’–
Analyzing ‘$2y$18$axMtQ4N8j/NQVItQJed9uORfsUK667RAWfycwFMtDBD6zAo1Se2eu’
[+] Blowfish(OpenBSD) [Hashcat Mode: 3200]
[+] Woltlab Burning Board 4.x
[+] bcrypt [Hashcat Mode: 3200]
–End of file ‘bcypt.txt’–

I had to use hash mode 3200

$ hashcat -m 3200 -a 3 -w 3 bcypt.txt

I guess hashrate is speed. Because I was using a VMWare virtual machine, I couldn’t use the GPU to crack the hashes. As a result, we see that there is speed for only one device. The allocated processor power of the virtual machine will not be enough for bitcoin mining.

Speed.#1………: 0 H/s (41.96ms) @ Accel:4 Loops:512 Thr:1 Vec:1

 

The Top tool showed that when the BCRYPT hash was cracked, the CPU usage was almost 400%, which means that almost all the power of four cores was used.

 

Also, the CPU usage of the Windows host machine was quite high.

 

John the Ripper

I tried to use the John the Ripper tool that comes preinstalled with the Kali linux distribution to crack passwords on local machines from the /etc/passwd and /etc/shadow files. I once did this in my homework for a penetration testing course, but here in Kali linux it didn’t work.

First I needed to unshadow the /etc/passwd and /etc/shadow files and redirect the output to a file.

$ sudo unshadow /etc/passwd /etc/shadow > shadow

 

Then, using john tool, I needed to crack passwords in an unshadowed file. But I always had the same error.

$ john –wordlist=/usr/share/wordlists/rockyou.txt  unshadowed
Using default input encoding: UTF-8
No password hashes loaded (see FAQ)

After some research and googling, I found that I need to use the –format=crypt option. It worked. Kali linux distribution has only one “kali” user by default and his “kali” password was cracked using John the Ripper tool.

 

Sources:

https://terokarvinen.com/2022/cracking-passwords-with-hashcat/

https://resources.infosecinstitute.com/topic/hashcat-tutorial-beginners/ 

https://hackware.ru/?p=4830

https://hashcat.net/wiki/doku.php?id=hashcat

https://samsclass.info/123/proj10/px16-hashcat-win.htm

https://security.stackexchange.com/questions/109211/john-the-ripper-is-not-identifying-hashes