Skip to content

evait-security/penv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

penv

Pentester Environment - A CLI tool for managing network and customer-specific environment variables across shell sessions on Linux.

Overview

penv auto-discovers network configuration and exposes it as shell variables. It supports saving/loading profiles for different customer environments, making it easy to switch contexts during engagements.

Variables are stored in ~/.local/share/penv/current.yaml and exported as lowercase shell variables (e.g., $ip, $dc, $domain) for direct use in commands like:

nxc smb $dc -d $domain -u $user -p $password

Installation

cargo build --release
cp target/release/penv ~/.local/bin/

Shell Setup

Add to your .bashrc or .zshrc:

eval "$(penv shell-init)"

This installs a wrapper function that:

  • Exports all variables from current.yaml on shell startup
  • Auto-reloads variables after penv set, penv unset, penv load, or penv discover

For fish shell:

eval (penv shell-init fish)

Manual mode: If you prefer explicit control, use eval "$(penv init)" instead. You'll need to re-run it after each change.

Usage

Auto-discover network environment

penv discover

Detects and saves:

  • ip - Local IP of the primary LAN adapter
  • gateway - Default gateway
  • dc - DNS server (useful as DC in AD environments)
  • domain - DNS search domain

Manage variables

penv set user "USERNAME"
penv set password "P@ssw0rd!"
penv unset password
penv list

Profile management

Save the current configuration as a named profile:

penv store customer_1

Load a saved profile:

penv load customer_1

With shell-init, variables are reloaded automatically.

Profiles are stored as ~/.local/share/penv/<name>.yaml.

Shell completions

Generate completions for your shell:

# Bash
penv completions bash > ~/.local/share/bash-completion/completions/penv

# Zsh
penv completions zsh > ~/.zfunc/_penv

# Fish
penv completions fish > ~/.config/fish/completions/penv.fish

Commands

Command Description
penv init Output export commands for eval
penv shell-init [shell] Output shell wrapper with auto-reload (bash/zsh/fish)
penv discover Auto-detect network info and save to current.yaml
penv set <key> <value> Add or update a variable
penv unset <key> Remove a variable
penv list Print all active variables
penv clean Wipe current.yaml
penv store <name> Save current state as a profile
penv load <name> Load a profile into current.yaml
penv completions <shell> Generate shell completions

Configuration Files

  • ~/.local/share/penv/current.yaml - Active configuration
  • ~/.local/share/penv/<profile>.yaml - Saved profiles

Example YAML:

vars:
  ip: 192.168.1.50
  gateway: 192.168.1.1
  dc: 192.168.1.10
  domain: corp.local
  user: administrator

Network Discovery

Discovery uses standard Linux tools with automatic fallbacks:

IP and Gateway:

  • ip route - Default route interface and gateway
  • ip addr - IP address of the default route interface

DNS Server and Domain (tried in order, merges results):

  1. resolvectl - systemd-resolved (only if active)
  2. nmcli - NetworkManager
  3. DHCP lease files:
    • /run/systemd/netif/leases/<ifindex> (systemd-networkd)
    • /var/lib/dhcp/dhclient.*.leases (dhclient)
  4. /run/systemd/resolve/resolv.conf - upstream DNS when using systemd stub
  5. /etc/resolv.conf - classic fallback

Works on systems with systemd-networkd, systemd-resolved, NetworkManager, dhclient, or plain resolv.conf.

License

MIT - see LICENSE

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages