# 4. Clear Logs to hide the Evidence of Compromise

## Clear Windows Machine Logs using Various Utilities <a href="#task-1-clear-windows-machine-logs-using-various-utilities" id="task-1-clear-windows-machine-logs-using-various-utilities"></a>

The system log file contains events that are logged by the OS components. These events are often predetermined by the OS itself. System log files may contain information about device changes, device drivers, system changes, events, operations, and other changes.

There are various Windows utilities that can be used to clear system logs such as Clear\_Event\_Viewer\_Logs.bat, wevtutil, and Cipher. Here, we will use these utilities to clear the Windows machine logs.

Right-click **Clear\_Event\_Viewer\_Logs.bat** and click **Run as administrator**.

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FV5sO2J3cMbkP9eCI3PYC%2Fimage.png?alt=media&#x26;token=2e145dcb-5463-428a-9625-1d0025a4b7ae" alt=""><figcaption></figcaption></figure>

A **Command Prompt** window appears, and the utility starts clearing the event logs, as shown in the screenshot. The command prompt will automatically close when finished.

Clear\_Event\_Viewer\_Logs.bat is a utility that can be used to wipe out the logs of the target system. This utility can be run through command prompt or PowerShell, and it uses a BAT file to delete security, system, and application logs on the target system. You can use this utility to wipe out logs as one method of covering your tracks on the target system.

### **wevtutil**

**el | enum-logs** lists event log names. Run **wevtutil cl \[log\_name]** command (here, we are clearing **system** logs) to clear a specific event log. **cl | clear-log**: clears a log, **log\_name** is the name of the log to clear, and ex: is the system, application, and security.

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FgLqS471yuaMoRvblFJBW%2Fimage.png?alt=media&#x26;token=2901ad42-b101-4929-8853-15abdd6dc140" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FIuLJNiLHFpIkC2WowPK3%2Fimage.png?alt=media&#x26;token=8bb1bd7b-4b5e-4804-a6c4-94a2e1cc2305" alt=""><figcaption></figcaption></figure>

Similarly, you can also clear application and security logs by issuing the same command with different log names (**application, security**).

### Cipher.exe

In **Command Prompt**, run **cipher /w:\[Drive or Folder or File Location]** command to overwrite deleted files in a specific drive, folder, or file. The Cipher.exe utility starts overwriting the deleted files, first, with all zeroes (0x00); second, with all 255s (0xFF); and finally, with random numbers, as shown in the screenshot.

Cipher.exe is an in-built Windows command-line tool that can be used to securely delete a chunk of data by overwriting it to prevent its possible recovery. This command also assists in encrypting and decrypting data in NTFS partitions.

When an attacker creates a malicious text file and encrypts it, at the time of the encryption process, a backup file is created. Therefore, in cases where the encryption process is interrupted, the backup file can be used to recover the data. After the completion of the encryption process, the backup file is deleted, but this deleted file can be recovered using data recovery software and can further be used by security personnel for investigation. To avoid data recovery and to cover their tracks, attackers use the Cipher.exe tool to overwrite the deleted files.

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FNQhKCkjNKabjoCRMGKNy%2Fimage.png?alt=media&#x26;token=1e2f7504-5956-49ac-8071-a79a29a35fa1" alt=""><figcaption></figcaption></figure>

## 2. Clear Linux Machine Logs using the BASH Shell <a href="#task-2-clear-linux-machine-logs-using-the-bash-shell" id="task-2-clear-linux-machine-logs-using-the-bash-shell"></a>

The BASH or Bourne Again Shell is a sh-compatible shell that stores command history in a file called bash history. You can view the saved command history using the more \~/.bash\_history command. This feature of BASH is a problem for hackers, as investigators could use the bash\_history file to track the origin of an attack and learn the exact commands used by the intruder to compromise the system.

Open a Terminal window and run **export HISTSIZE=0** command to disable the BASH shell from saving the history.\
In the **Terminal** window, run **history -c** command to clear the stored history.

This command is an effective alternative to the disabling history command; with **history -c**, you have the convenience of rewriting or reviewing the earlier used commands.

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FEc93L7724DBQt9gu1FGL%2Fimage.png?alt=media&#x26;token=c3b304ea-fb3d-4d6f-9338-f3f450db58d8" alt=""><figcaption></figcaption></figure>

Similarly, you can also use the **history -w** command to delete the history of the current shell, leaving the command history of other shells unaffected. Run **shred \~/.bash\_history** command to shred the history file, making its content unreadable.

```
shred ~/.bash_history && cat /dev/null > .bash_history && history -c && exit
```

This command first shreds the history file, then deletes it, and finally clears the evidence of using this command. After this command, you will exit from the terminal window.

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2F4pUUvvvYv39EOYLAQidG%2Fimage.png?alt=media&#x26;token=f6677b46-6417-430f-9594-49165e4bc5cd" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">3. View, Edit and clear Audit Policies using Auditpol</mark>

Auditpol.exe is the command-line utility tool to change the Audit Security settings at the category and sub-category levels. You can use Auditpol to enable or disable security auditing on local or remote systems and to adjust the audit criteria for different categories of security events. In real-time, the moment intruders gain administrative privileges, they disable auditing with the help of auditpol.exe. Once they complete their mission, they turn auditing back on by using the same tool (audit.exe).

See all audit policies

```
auditpol /get /category:*
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FyLVvGIrGOxQB2o9s9apf%2Fimage.png?alt=media&#x26;token=29ca55c2-4663-4706-bdd0-49e1b4e361d8" alt=""><figcaption></figcaption></figure>

To set an auditing policy

```
auditpol /set /category:"system","account logon" /success:enable /failure:enable
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FjGJ59XMjHBz1IQsIWD21%2Fimage.png?alt=media&#x26;token=799457b8-25f6-4184-85c1-d66457835f8a" alt=""><figcaption></figcaption></figure>

To clear all audit policies

```
auditpol /clear /y
```

## <mark style="color:red;">4. Clear windows logs using different utilities</mark>

**Bat Script**

{% embed url="<https://www.tenforums.com/tutorials/16588-clear-all-event-logs-event-viewer-windows.html>" %}

Download the script and run as administrator.

**wevtutil el**

list event logs

```
wevtutil el
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FSZYU1M78o4GpWtUs4sjH%2Fimage.png?alt=media&#x26;token=9f947a3b-232c-43e0-ab44-51c8feb80952" alt=""><figcaption></figcaption></figure>

To clear a single log

```
wevtutil cl system  \\system is the log name
```

To clear all logs

```
for /F "tokens=*" %1 in ('wevtutil.exe el') DO wevtutil.exe cl "%1"
```

**Cipher (Overwrite deleted files)**

```
cipher /w:c:
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FMfTUu6hm9xEdtgJ6Uty9%2Fimage.png?alt=media&#x26;token=c1c12df1-d1f6-4689-8908-d40119f8b218" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">5. Clear Linux logs using bash shell</mark>

Disable history keeping

```
export HISTSIZE=0
```

To clear bash history

```
history -c
```

clear history of existing shell only

```
history -w
```

shred the history without clearing

```
shred ~/.bash_history
```

to view history file

```
more ~/.bash_history
```

First shred history file and then clear it.

```
shred ~/.bash_history && cat /dev/null>.bash_history && history -c && exit
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FimcS9fzknXI9j1k4rPUb%2Fimage.png?alt=media&#x26;token=811bf97c-80e2-43e3-9528-74a5ef12da28" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">6. Hiding Artifacts in Windows and Linux</mark>

### Windows

create a dir

```
mkdir test
```

Hide a folder in windows

```
attrib +h +r +s test
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FCNnoNH4pBWcHhO11bAhq%2Fimage.png?alt=media&#x26;token=7e81597c-3b61-48f0-bce0-de4e65d550ff" alt=""><figcaption></figcaption></figure>

To unhide a folder in windows

```
attrib -s -h -r test
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2FWwkE5boOdyc6ZTuFXt8V%2Fimage.png?alt=media&#x26;token=a53d79a8-d91a-42dd-b19c-a1c1115a675e" alt=""><figcaption></figcaption></figure>

Hide user accounts in windows

```
net user test /add
net user test /active:yes
net user test /active:no      \\hides the account
```

### Linux

Create a file with **.** to hide a file. Ti view the hidden files

```
ls -la
```

<figure><img src="https://2218819509-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrUBnODuUX4EQ8P27uc5D%2Fuploads%2F8VeCRKlQ6UHbH4YlxUmH%2Fimage.png?alt=media&#x26;token=d663c76e-be78-49af-91c3-97d5e8f4bbbf" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">7. Clear window logs using CCleaner</mark>

{% embed url="<https://www.ccleaner.com/ccleaner/download>" %}

### CEHv13 Practical Course

{% embed url="<https://www.udemy.com/course/ethical-hacker-practical/?referralCode=289CF01CF51246BCAD6C>" %}
