Skip to content

ymuuuu/AddToHosts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 

Repository files navigation

AddToHosts

Demo License

A PowerShell script to simplify adding entries to Windows and WSL (Kali Linux) hosts files, with automatic backups and duplicate checks. Perfect for CTF setups, local development, or network testing.

Features โœจ

  • Cross-Platform Support: Updates hosts files for both Windows and WSL (Kali Linux) (See below if you want other distros).
  • Automatic Backups: Creates hosts.bak on first run for easy recovery.
  • Duplicate Prevention: Skips existing entries to avoid clutter.
  • Admin-Friendly: Auto-elevates to admin rights when needed.

Installation ๐Ÿ“ฅ

  1. Prerequisites:

    • Windows 10/11 with PowerShell 5.1+.
    • WSL with Kali Linux installed (default distro name: kali-linux).
  2. Clone the Repository:

    git clone https://github.com/ymuuuu/AddToHosts.git
    cd AddToHosts

Usage ๐Ÿš€

Run the script as Administrator:

.\AddTo-Hosts.ps1

Example Workflow:

Enter IP (e.g., 10.10.11.55): 10.10.11.123
Enter hostname (e.g., titanic.htb): ctf-target.htb

[*] Windows backup already exists: C:\Windows\System32\drivers\etc\hosts.bak
[*] WSL backup already exists: /etc/hosts.bak

[+] Windows hosts: Added '10.10.11.123 ctf-target.htb'
[+] Added to WSL Kali hosts: 10.10.11.123 ctf-target.htb

Press any key to exit...

Restore Backups ๐Ÿ”„

Windows

Copy-Item "$env:SystemRoot\System32\drivers\etc\hosts.bak" "$env:SystemRoot\System32\drivers\etc\hosts" -Force

WSL (Kali Linux)

sudo cp /etc/hosts.bak /etc/hosts

Will It Work with Other WSL Distributions?

Yes! You can easily modify it to work with any WSL distribution (e.g., Ubuntu, Debian). Hereโ€™s how:

  1. Check Your WSL Distribution Name Run this in PowerShell to list installed WSL distros:
wsl -l -q

Example output:

Ubuntu
kali-linux
Debian
  1. Update the Script Replace kali-linux in the script with your distribution name. For example:
# For Ubuntu
wsl -d Ubuntu -u root bash -c ...

# For Debian
wsl -d Debian -u root bash -c ...

Security Note ๐Ÿ”’

  • Requires admin rights to modify system files.
  • Backups are created only once to prevent accidental overwrites.
  • Script exits immediately on cancellation.

License ๐Ÿ“„

MIT License - See LICENSE.

Happy Hacking! ๐ŸŽฎ๐Ÿ”
Feel free to contribute or report issues!

About

A PowerShell script to simplify adding entries to Windows and WSL (Kali Linux) hosts files, with automatic backups and duplicate checks. Perfect for CTF setups, local development, or network testing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors