tags: Filtri_Linux AWK


L’esempio di file sul quale andremo a lavorare per gli esempi è il seguente:

nxc smb cicada.htb -u 'Guest' -p '' --rid-brute
SMB         10.129.231.149  445    CICADA-DC        [*] Windows Server 2022 Build 20348 x64 (name:CICADA-DC) (domain:cicada.htb) (signing:True) (SMBv1:None) (Null Auth:True)
SMB         10.129.231.149  445    CICADA-DC        [+] cicada.htb\Guest: 
SMB         10.129.231.149  445    CICADA-DC        498: CICADA\Enterprise Read-only Domain Controllers (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        500: CICADA\Administrator (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        501: CICADA\Guest (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        502: CICADA\krbtgt (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        512: CICADA\Domain Admins (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        513: CICADA\Domain Users (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        514: CICADA\Domain Guests (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        515: CICADA\Domain Computers (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        516: CICADA\Domain Controllers (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        517: CICADA\Cert Publishers (SidTypeAlias)
SMB         10.129.231.149  445    CICADA-DC        518: CICADA\Schema Admins (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        519: CICADA\Enterprise Admins (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        520: CICADA\Group Policy Creator Owners (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        521: CICADA\Read-only Domain Controllers (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        522: CICADA\Cloneable Domain Controllers (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        525: CICADA\Protected Users (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        526: CICADA\Key Admins (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        527: CICADA\Enterprise Key Admins (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        553: CICADA\RAS and IAS Servers (SidTypeAlias)
SMB         10.129.231.149  445    CICADA-DC        571: CICADA\Allowed RODC Password Replication Group (SidTypeAlias)
SMB         10.129.231.149  445    CICADA-DC        572: CICADA\Denied RODC Password Replication Group (SidTypeAlias)
SMB         10.129.231.149  445    CICADA-DC        1000: CICADA\CICADA-DC$ (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1101: CICADA\DnsAdmins (SidTypeAlias)
SMB         10.129.231.149  445    CICADA-DC        1102: CICADA\DnsUpdateProxy (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        1103: CICADA\Groups (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        1104: CICADA\john.smoulder (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1105: CICADA\sarah.dantelia (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1106: CICADA\michael.wrightson (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1108: CICADA\david.orelious (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1109: CICADA\Dev Support (SidTypeGroup)
SMB         10.129.231.149  445    CICADA-DC        1601: CICADA\emily.oscars (SidTypeUser)

Questo comando intelligente ti divide il testo in colonne e ogni numero dopo il $ indica la colonna che vogliamo vedere per esempio la colonna 6 indica:

cat output.txt | awk '{ print $6 }'
Windows
cicada.htb\Guest:
CICADA\Enterprise
CICADA\Administrator
CICADA\Guest
CICADA\krbtgt
CICADA\Domain
CICADA\Domain
CICADA\Domain
CICADA\Domain
CICADA\Domain
CICADA\Cert
CICADA\Schema
CICADA\Enterprise
CICADA\Group
CICADA\Read-only
CICADA\Cloneable
CICADA\Protected
CICADA\Key
CICADA\Enterprise
CICADA\RAS
CICADA\Allowed
CICADA\Denied
CICADA\CICADA-DC$
CICADA\DnsAdmins
CICADA\DnsUpdateProxy
CICADA\Groups
CICADA\john.smoulder
CICADA\sarah.dantelia
CICADA\michael.wrightson
CICADA\david.orelious
CICADA\Dev
CICADA\emily.oscars

Oppure la colonna 2 gli indirizzi IP:

cat output.txt | awk '{ print $2 }'
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149
10.129.231.149

Scegliere in un Range

Questo comando ti permette di ottenere solo i risultati che hanno un valore di RID superiore a 999:

 
cat esercizio.txt | awk '$5 + 0 > 999 { print }'
 
SMB         10.129.231.149  445    CICADA-DC        1000: CICADA\CICADA-DC$ (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1104: CICADA\john.smoulder (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1105: CICADA\sarah.dantelia (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1106: CICADA\michael.wrightson (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1108: CICADA\david.orelious (SidTypeUser)
SMB         10.129.231.149  445    CICADA-DC        1601: CICADA\emily.oscars (SidTypeUser)
  • $6 = la colonna 6 (dove c’è il RID)
  • + 0 = convertila a numero
  • > 999 = confronto matematico
  • { print } = stampa le righe che soddisfano la condizione

Ingrandire tutti i caratteri

cat output.txt | grep "SidTypeUser" | awk '{ print toupper($6) }'
 
CICADA\ADMINISTRATOR
CICADA\GUEST
CICADA\KRBTGT
CICADA\CICADA-DC$
CICADA\JOHN.SMOULDER
CICADA\SARAH.DANTELIA
CICADA\MICHAEL.WRIGHTSON
CICADA\DAVID.ORELIOUS