> For the complete documentation index, see [llms.txt](https://kranyyy.gitbook.io/cyber/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kranyyy.gitbook.io/cyber/practica-4_4-splunk-exploring-spl.md).

# Practica 4\_4 Splunk exploring spl

![](/files/xJrx9Qgo7rVKYCTJ5g6u)<br>

**TASK 2**

Vamos a comenzar entrando a la maquina:

![](/files/uqzej3rDKbzVaN3CFfQn)

Clickamos en search and reporting:

![](/files/ynbXSBV3HvigThsV6Fqa)

Y como nos dice tryhackme trabajaremos sobre el index=”windowslogs” , aquí ya podemos ver el nombre del host.

**TASK 3**

Vamos a comenzar yéndonos al serach history que esta al principio y buscamos el séptimo filtro que se utilizo quitando los dos primeros que escribi yo:

![](/files/rJMWWnQHw7hL2ZLjMYc4)

Para saber que ip es la que mas eventos genero :

![](/files/gHnnAVoJOVEzayffx91Q)

Como podemos ver fue la 172.90.12.11 , ya que las primeras no cuentan por que es mi propia maquina.

Para la siguiente maquina vamos a poner el filtro de tiempo que nos dicen en tryhackme y ver el numero de eventos que se generaron:

![](/files/I5ZYVZS4cIKopSvWTCzp)

![](/files/Un2zE2v2dymmxjDRPsLU)

**TASK 4**

(info de marcadores para splunk)

Comparison Operators

﻿These operators are used to compare the values against the fields. Some common comparisons operators are mentioned below:<br>

| <p>Field Name<br></p>               | <p>Operator<br></p> | <p>Example<br></p>                   | <p>Explanation<br></p>                                                                                                                                                        |
| ----------------------------------- | ------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>Equal<br></p>                    | <p>=<br></p>        | UserName=Mark                        | <p>This operator is used to match values against the field. In this example, it will look for all the events, where the value of the field UserName is equal to Mark.<br></p> |
| <p>Not Equal to<br></p>             | <p>!=<br></p>       | UserName!=Mark                       | <p>This operator returns all the events where the UserName value does not match Mark.<br></p>                                                                                 |
| <p>Less than<br></p>                | <p><<br></p>        | Age < 10                             | <p>Showing all the events with the value of Age less than 10.<br></p>                                                                                                         |
| <p>Less than or Equal to<br></p>    | <p><=<br></p>       | Age <= 10                            | Showing all the events with the value of Age less than or equal to 10.                                                                                                        |
| <p>Greater than<br></p>             | <p>><br></p>        | <p>Outbound\_traffic > 50 MB<br></p> | <p>This will return all the events where the Outbound traffic value is over 50 MB.<br></p>                                                                                    |
| <p>Greater Than or Equal to<br></p> | <p>>=<br></p>       | Outbound\_traffic >= 50 MB           | This will return all the events where the Outbound traffic value is greater or equal to 50 MB.                                                                                |

﻿﻿Lets use the comparison operator to display all the event logs from the index "windowslogs", where AccountName is not Equal to "System"

Search Query: `index=windowslogs AccountName !=SYSTEM`<br>

<div align="center"><img src="https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/681a126a98263612b87def7014583ffb.png" alt=""></div>

Boolean Operators

Splunk supports the following Boolean operators, which can be very handy in searching/filtering and narrowing down results.<br>

| <p>Operator<br></p> | <p>Syntax<br></p>                             | <p>Explanation<br></p>                                                                   |
| ------------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------- |
| <p>NOT<br></p>      | <p>field\_A NOT value<br></p>                 | <p>Ignore the events from the result where field\_A contain the specified value.<br></p> |
| <p>OR<br></p>       | <p>field\_A=value1 OR field\_A=value2<br></p> | <p>Return all the events in which field\_A contains either value1 or value2.<br></p>     |
| <p>AND<br></p>      | field\_A=value1 AND field\_B=value2           | Return all the events in which field\_A contains value1 and field\_B contains value2.    |

﻿To understand how boolean operator works in SPL, lets add the condition to show the events from the James account.

Search Query: `index=windowslogs AccountName !=SYSTEM AND AccountName=James`<br>

<div align="center"><img src="https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/42c8963dccbd05128f52665c38877f47.png" alt=""></div>

Wild Card

Splunk supports wildcards to match the characters in the strings.<br>

| Wildcard symbol   | <p>Example   <br></p> | <p>Explanation         <br></p>                                                                     |
| ----------------- | --------------------- | --------------------------------------------------------------------------------------------------- |
| <p>\*<br><br></p> | status=fail\*         | <p>It will return all the results with values like</p><p>status=failed</p><p>status=failure<br></p> |

In the events, there are multiple DestinationIPs reported. Let's use the wildcard only to show the DestinationIP starting from 172.\*

Search Query: `index=windowslogs DestinationIp=172.*`<br>

<div align="center"><img src="https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/5530cae0739755e6a682641f5057b1a5.png" alt=""></div>

Para el primer ejercicio nos pide cuantos eventos hay con el eventid = 1 y el nombre “\*James\*” , CUIDADO CON LAS MAYUSCULAS AL PRINCIPIO DE CADA FLAG!!!!:

![](/files/zA7EMPdPjHUoX38tyhxu)

Luego nos piden los eventos con una ip y un puerto concreto :

![](/files/uCCvGvUawHFGNuNi7JPn)

A continuación dada una query ya por thm , ver que source ip tiene mas counts:

![](/files/mE0ZG6m5HjqYzxi7T4UQ)

![](/files/y3jz5kV8Lz1c32hLDDgs)

Luego nos piden el numero de eventos que contengan el nombre cyber:

![](/files/qPWyYlvoewCxWGVUSK8z)

Respueta 0

Pero con cyber\*:

![](/files/HVo64Wpo3w7nQVD62Eae)

**TASK 5**

Fields

| <p>Command<br></p>     | <p>fields                                                                                               <br></p>                                                                                                                   |                                                  |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| <p>Explanation<br></p> | <p>Fields command is used to add or remove mentioned fields from the search results. To remove the field, minus sign ( - ) is used before the fieldname and plus ( + ) is used before the fields which we want to display.<br></p> |                                                  |
| <p>Syntax<br></p>      | \| fields \<field\_name1>  \<field\_name2>                                                                                                                                                                                         |                                                  |
| <p>Example<br></p>     | <p>                                                                                                                                                                                                                                | <code>fields + HostName - EventID</code><br></p> |

Let's use the fields command to only display host, User, and SourceIP fields using the following syntax.<br>

Search Query: `index=windowslogs | fields + host + User + SourceIp`<br>

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/dd77983b5fccf5eacfa73aacbeb7a314.png)<br>

Note: Click on the More field to display the fields if some fields are not visible.

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/30b2c651a041bd1c2db77b661dc8cc8e.png)<br>

Search

| <p>Command<br></p>     | <p>search                                                                                               <br></p> |                                          |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| <p>Explanation<br></p> | This command is used to search for the raw text while using the chaining command `\|`                            |                                          |
| <p>Syntax<br></p>      | <p>                                                                                                              | search  \<search\_keyword><br></p>       |
| <p>Example<br></p>     | <p>                                                                                                              | <code>search "Powershell"</code><br></p> |

Use the search command to show all the events containing the term Powershell. This will return all the events that contain the term "Powershell".<br>

Search Query: `index=windowslogs | search Powershell`<br>

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/02d2ece97e7f977e32b4c11fd86e41eb.png)<br>

Dedup

| <p>Command<br></p>     | <p>dedup                                                                                        <br></p>                                                                                                             |                                    |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| <p>Explanation<br></p> | Dedup is the command used to remove duplicate fields from the search results. We often get the results with various fields getting the same results. These commands remove the duplicates to show the unique values. |                                    |
| <p>Syntax<br></p>      | <p>                                                                                                                                                                                                                  | dedup \<fieldname><br></p>         |
| <p>Example<br></p>     | <p>                                                                                                                                                                                                                  | <code>dedup EventID</code><br></p> |

We can use the dedup command to show the list of unique EventIDs from a particular hostname.

Search Query: `index=windowslogs | table EventID User Image Hostname | dedup EventID`

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/47bb3fb904c84acdbe7cb89dda535ac1.png)<br>

Rename

| <p>Command<br></p>     | <p>rename<br></p>                                                                                                                                                              |                              |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- |
| <p>Explanation<br></p> | It allows us to change the name of the field in the search results. It is useful in a scenario when the field name is generic or log, or it needs to be updated in the output. |                              |
| <p>Syntax<br></p>      | <p>                                                                                                                                                                            | rename  \<fieldname><br></p> |
| <p>Example<br></p>     | \| `rename User as Employees`                                                                                                                                                  |                              |

Let's rename the User field to Employees using the following search query.

Search Query: `index=windowslogs | fields + host + User + SourceIp | rename User as Employees`<br>

<div align="center"><img src="https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/61e56df15649aa12b4be7c91d8cc91ce.png" alt=""></div>

Para el primer ejercicio que te pide el event id de la 3 linea dada el filtro en thm:

4103

Para el segundo ejercicio te dice que de la query anterior antes del reverse le hagas un dedup Hostname y digas el nombre del primer hostname:

Salena.adam

**TASK 6**

SPL provides various commands to bring structure or order to the search results. These sorting commands like `head`, `tail`, and `sort` can be very useful during logs investigation. These ordering commands are explained below:

Table<br>

| <p>Explanation<br></p> | Each event has multiple fields, and not every field is important to display. The Table command allows us to create a table with selective fields as columns. |                                                 |                                                                                |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- | ------------------------------------------------------------------------------ |
| <p>Syntax<br></p>      | <p>                                                                                                                                                          | table \<field\_name1> \<fieldname\_2>  <br></p> |                                                                                |
| <p>Example<br></p>     | <p>                                                                                                                                                          | <code>table</code><br></p><p>                   | <code>head 20</code> # will return the top 20 events from the result list.</p> |

This search query will create a table with three columns selected and ignore all the remaining columns from the display.<br>

Search Query: `index=windowslogs | table EventID Hostname SourceName`

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/643f5cc127276645eb0fd7fdb339cb29.png)\
\
Head

| <p>Explanation<br></p> | <p>The head command returns the first 10 events if no number is specified.<br></p> |                                                                                     |                                                                                      |
| ---------------------- | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| <p>Syntax<br></p>      | <p>                                                                                | head \<number>   <br></p>                                                           |                                                                                      |
| <p>Example<br></p>     | <p>                                                                                | <code>head</code>   # will return the top 10 events from the result list<br></p><p> | <code>head 20</code>    # will return the top 20 events from the result list<br></p> |

The following search query will show the table containing the mentioned fields and display only the top 5 entries.<br>

Search Query: `index=windowslogs |  table _time EventID Hostname SourceName | head 5`<br>

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/3a9df7382d1f5e2e3302750dc5016809.png)<br>

Tail

| <p>Explanation<br></p> | The Tail command returns the last 10 events if no number is specified. |                                                                                    |                                                                                  |
| ---------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| <p>Syntax<br></p>      | \| tail \<number>                                                      |                                                                                    |                                                                                  |
| <p>Example<br></p>     | <p>                                                                    | <code>tail</code> # will return the last 10 events from the result list<br></p><p> | <code>tail 20</code>   # will return the last 20 events from the result list</p> |

The following search query will show the table containing the mentioned fields and display only 5 entries from the bottom of the list.<br>

Search Query: `index=windowslogs |  table _time EventID Hostname SourceName | tail 5`

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/917811648cc95bd3f34c820a473b9c1b.png)<br>

sort<br>

| <p>Explanation<br></p> | <p>The Sort command allows us to order the fields in ascending or descending order.<br></p> |                                            |
| ---------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------ |
| <p>Syntax<br></p>      | <p>                                                                                         | <code>sort</code> \<field\_name>  <br></p> |
| <p>Example<br></p>     | \| `sort Hostname` # This will sort the result in Ascending order.                          |                                            |

The following search query will sort the results based on the Hostname field.

Search Query: `index=windowslogs |  table _time EventID Hostname SourceName | sort Hostname`<br>

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/9589d101b5a07f69fc4771a6c1e54e14.png)\ <br>

Reverse

| <p>Explanation<br></p> | <p>The reverse command simply reverses the order of the events.<br></p> |                                                                                                                                                      |
| ---------------------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>Syntax<br></p>      | \|  reverse                                                             |                                                                                                                                                      |
| <p>Example<br></p>     | <p><code>\<Search Query>                                                | reverse</code>                                                                                                                              <br></p> |

Search Query: `index=windowslogs | table _time EventID Hostname SourceName | reverse`<br>

<div align="center"><img src="https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/0de4064ec74ee5f64a399e0a7bed9200.png" alt=""></div>

Nos piden el nombre del hostname de hacerl el reverse a la query que nos da thm:

<figure><img src="/files/GHOILGDAFJ8z7468EELF" alt=""><figcaption></figcaption></figure>

Ahora te piden que a la primera query le hagas un tail y digas el ultimo eventid:

<figure><img src="/files/lsL5cCGgm1oDwQ4hiYln" alt=""><figcaption></figcaption></figure>

4103

Y por ultimo que hagas un sort en el sourcename:

<figure><img src="/files/W7UGlsfaG6rQAMMMCafi" alt=""><figcaption></figcaption></figure>

**TASK 7**

Transformational commands are those commands that change the result into a data structure from the field-value pairs. These commands simply transform specific values for each event into numerical values which can easily be utilized for statistical purposes or turn the results into visualizations. Searches that use these transforming commands are called transforming searches. Some of the most used transforming commands are explained below.

General Transformational Commands<br>

Top<br>

| <p>Command<br></p>     | <p>top<br></p>                                              |                            |                                    |
| ---------------------- | ----------------------------------------------------------- | -------------------------- | ---------------------------------- |
| <p>Explanation<br></p> | This command returns frequent values for the top 10 events. |                            |                                    |
| <p>Syntax<br></p>      | <p>                                                         | top  \<field\_name></p><p> | top limit=6 \<field\_name><br></p> |
| <p>Example<br></p>     | `top limit=3 EventID`                                       |                            |                                    |

The following command will display the top 7 Image ( representing Processes) captured.

Search Query: `index=windowslogs | top limit=7 Image`

\
![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/ffef6c0a6ce0159e6d970de2c32921a3.png)<br>

Rare<br>

| <p>Command<br></p>     | <p>rare<br></p>                                                                                             |                            |                                     |
| ---------------------- | ----------------------------------------------------------------------------------------------------------- | -------------------------- | ----------------------------------- |
| <p>Explanation<br></p> | This command does the opposite of top command as it returns the least frequent values or bottom 10 results. |                            |                                     |
| <p>Syntax<br></p>      | <p>                                                                                                         | rare \<field\_name></p><p> | rare limit=6 \<field\_name><br></p> |
| <p>Example<br></p>     | `rare limit=3 EventID`                                                                                      |                            |                                     |

The following command will display the rare 7 Image (Processes) captured.

Search Query: `index=windowslogs | rare limit=7 Image`<br>

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/8123e0932c169514d9842fbba8f5898c.png)<br>

Highlight

| <p>Command<br></p>     | <p>highlight<br></p>                                                                |
| ---------------------- | ----------------------------------------------------------------------------------- |
| <p>Explanation<br></p> | The highlight command shows the results in raw events mode with fields highlighted. |
| <p>Syntax<br></p>      | highlight      \<field\_name1>      \<field\_name2>                                 |
| <p>Example<br></p>     | `highlight User, host, EventID, Image`                                              |

The following command will highlight the three mentioned fields in the raw logs<br>

Search Query: `index=windowslogs | highlight User, host, EventID, Image`

<br>

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/61ad47b204639fa0f75b278bec21abac.gif)<br>

<br>

STATS Commands

SPL supports various stats commands that help in calculating statistics on the values. Some common stat commands are:

| <p>Command<br></p> | <p>Explanation<br></p>                                            | <p>Syntax<br></p>                  | <p>Example<br></p>                  |
| ------------------ | ----------------------------------------------------------------- | ---------------------------------- | ----------------------------------- |
| <p>Average<br></p> | This command is used to calculate the average of the given field. | stats avg(field\_name)             | stats avg(product\_price)           |
| <p>Max<br></p>     | It will return the maximum value from the specific field.         | stats max(field\_name)             | stats max(user\_age)                |
| <p>Min<br></p>     | It will return the minimum value from the specific field.         | stats min(field\_name)             | stats min(product\_price)           |
| <p>Sum<br></p>     | It will return the sum of the fields in a specific value.         | stats sum(field\_name)             | <p>stats sum(product\_cost)<br></p> |
| <p>Count<br></p>   | The count command returns the number of data occurrences.         | stats count(function) AS new\_NAME | stats count(source\_IP)             |

Splunk Chart Commands<br>

These are very important types of transforming commands that are used to present the data in table or visualization form. Most of the chart commands utilize various stat commands.

Chart

| <p>Command<br></p>     | <p>chart<br></p>                                                                          |                           |
| ---------------------- | ----------------------------------------------------------------------------------------- | ------------------------- |
| <p>Explanation<br></p> | <p>The chart command is used to transform the data into tables or visualizations.<br></p> |                           |
| <p>Syntax<br></p>      | <p>                                                                                       | chart \<function><br></p> |
| <p>Example<br></p>     | \| `chart count by User`                                                                  |                           |

Search Query: `index=windowslogs | chart count by User`

![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/a954b0a1d37542650df294461d756c61.gif)<br>

Timechart

| <p>Command<br></p>     | <p>timechart<br></p>                                                                                                                         |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>Explanation<br></p> | The timechart command returns the time series chart covering the field following the function mentioned. Often combined with STATS commands. |
| <p>Syntax<br></p>      | \| timechart function  \<field\_name>                                                                                                        |
| <p>Example<br></p>     | \| `timechart count by Image`                                                                                                                |

The following query will display the Image chart based on the time.<br>

Search Query: `index=windowslogs | timechart count by Image`

\
![](https://tryhackme-images.s3.amazonaws.com/user-uploads/5e8dd9a4a45e18443162feab/room-content/bc7f90e4f40be4c047d250d5e3ee44c8.gif)

Cual es el top 6 de imágenes y di el numero ce counts:

<figure><img src="/files/pQApQcZrmkafNP3LwpkW" alt=""><figcaption></figcaption></figure>

196

En el siguiente ejercicio nos piden el usuario con menos counts por medio del comando rare :&#x20;

<figure><img src="/files/dQjG6oLOHv6ExXCq0513" alt=""><figcaption></figcaption></figure>

James

Y para el ultimo:

<figure><img src="/files/cktjPvthhyGfJPcOLLSl" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/h9TFsXNqO8aUZanu0zvd" alt=""><figcaption></figcaption></figure>
