Nagios check_email_delivery plugin not resolving cnames - perl

I'm using the Nagios plugin check_email_delivery to monitor email, and to check software statuses in some cases. We're now moving all of our internal mail servers to Office 365 and have discovered that this command:
./check_imap_receive_epn -H outlook.office365.com -U user#example.com -P password --ssl -s SUBJECT -s $ARG1$ -w 1200 -c 1800
Results in:
IMAP RECEIVE CRITICAL - Could not connect to outlook.office365.com port 993: IO::Socket::INET6 configuration failederror:00000000:lib(0):func(0):reason(0) at ./check_imap_receive_epn line 93.
HOWEVER! Resolving the cname to an IP address seems to work. Example:
./check_imap_receive_epn -H 157.56.239.201 -U user#example.com -P password --ssl -s SUBJECT -s $ARG1$ -w 1200 -c 1800
With a result of:
IMAP RECEIVE OK - 5 seconds, 1 found, 1 deleted
I think the issue is caused here:
my $socket = IO::Socket::SSL->new(PeerAddr=>"$imap_server:$imap_port", %ssl_args);
Where $imap_server isn't resolving correctly. Any suggestions? >.<

because IO::Socket::INET6 is installed IO::Socket::SSL will use this as base class.
IO::Socket::INET6 tries to get an IPv6 address first (e.g. DNS AAAA record), while ping etc often try IPv4 only (there is usually a ping6 to for IPv6). So if your IPv6 setup is broken you might not realize it with IPv4-only tools. Please check:
dig outlook.office365.com AAAA - this should give you IPv6 addresses.
If you don't have IPv6 it should give no records at all and NOERROR, but some broken resolvers return NXDOMAIN instead
if you get an IPv6 address try to connect to it, e.g.
perl -MIO::Socket::INET6 -e 'IO::Socket::INET6->new("[2a01:111:f400:9800::6]:993") or die $!'
If you get an error your IPv6 setup is broken, e.g. the resolver returns IPv6 records even you cannot reach hosts by IPv6

Related

How to connect to windows postgres Database from WSL

I'm running Postgres 11 service on my Windows computer.
How can I connect to this database from WSL?
When I try su - postgres:
postgres#LAPTOP-NQ52TKOG:~$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"
It's trying to connect to a Postgres in WSL. I don't want to run Ubuntu Postgres using:
sudo /etc/init.d/postgresql start
WSL2 assigns IP address to the Windows host dynamically and the IP addresses can change without even rebooting Windows (see Notes below). So to reliably connect we'll need to:
Allow Windows and Postgres to accept connections from the WSL2 IP address range (not allowed by default)
From WSL2, determine the Windows/Postgresql host's IP address (which is dynamic) when connecting via psql. We'll make this convenient via .bashrc and alias.
Unfortunately I couldn't find the exact specification for the WSL2 IP address range. From several tests/reboots it appears that WSL2 is assigning IP addresses primarily in range of 172.*.*.* but I have occasionally been assigned 192.*.*.* so we'll use these when configuring the firewall and Postgres.
Add Windows Firewall Inbound Port Rule for WSL2 IP Addresses:
Open Windows Defender Firewall with Advanced Security
Click New Rule...
Select Port for rule type
Select TCP and for Specific local ports enter 5432
Select Allow the connection. Connecting from WSL2 won't be secure so don't select the secure option
Select at least Public. Can select Domain and Private as well. I could only connect if Public was selected
Name the rule e.g. Postgres - connect from WSL2 and create it
Right click newly created rule and select Properties then click on the Scope tab
Under Remote IP address, select These IP addresses then click Add... and enter range 172.0.0.1 to 172.254.254.254
Repeat step 9 for IP address range 192.0.0.1 to 192.254.254.254
Click Apply then OK
Make sure rule is enabled
Configure Postgres to Accept Connections from WSL2 IP Addresses
Assuming a default install/setup of Postgresql for Windows the following files are located under C:\Program Files\PostgresSQL\$VERSION\data
Verify that postgresql.conf has following set:
listen_addresses = '*'
This should already be set to '*' so nothing do here.
Update pg_hba.conf to allow connections from WSL2 range e.g. for Postgresl 12:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 172.0.0.0/8 md5
host all all 192.0.0.0/8 md5
For Postgresql 13+ you should use scram-sha-256 as the method.
Restart Postgres for changes to take effect. This can be done either from the Windows Services app or from cmd with Administrator privileges e.g. for Postgresql 12:
net stop postgresql-x64-12
net start postgresql-x64-12
WSL Shell Conveniences
In WSL, add following to your ~/.bashrc or similar:
# Add DNS entry for Windows host
if ! $(cat /etc/hosts | grep -q 'winhost'); then
echo 'Adding DNS entry for Windows host in /etc/hosts'
echo '\n# Windows host - added via ~/.bashhrc' | sudo tee -a /etc/hosts
echo -e "$(grep nameserver /etc/resolv.conf | awk '{print $2, " winhost"}')" | sudo tee -a /etc/hosts
fi
Then reload your .bashrc changes: source ~/.bashrc
Usage
psql -h winhost -p 5432 -U postgres
Notes:
The IP address assigned to the Windows host by WSL2 is not the same as the IP address assigned to your physical Windows machine on your network. WSL2 uses vEthernet connections.
You can inspect the vEthernet connections via Control Panel\Network and Internet\Network Connections
Note that when looking at the IPv4 properties that the IP addresses will appear as if they are statically set but they aren't! Try rebooting and inspecting IPv4 properties again
If one day you're unable to connect to Postgres, check that winhost is in the IP address range per firewall rules. Could be WSL has assigned an IP address that we weren't expecting!
In WSL2 you need to use host IP to connect
to get host IP
grep nameserver /etc/resolv.conf | awk '{print $2}'
then you need to allow TCP 5432 inbound Rules in 'Windows Defender Firewall with Advanced Security'
I made my self PS.you still need to allow TCP 5432 in Firewall
put this in ~/.bashrc
cat /etc/hosts | grep 172.; test $? -eq 0 && $1 || echo -e "$(grep nameserver /etc/resolv.conf | awk '{print $2, " host"}')\n$(cat /etc/hosts)" | sudo tee /etc/hosts
its append host IP to /etc/hosts if not exist before(usually happened when restart wsl or computer)
then
psql -h host -p 5432 -U postgres
Specify your host, port, and username explicitly
For example:
psql -h 127.0.0.1 -p 5432 -U postgres
For me what worked was to follow these steps:
Change pg_hba.conf to listen on all interfaces: host all all 0.0.0.0/0 trust
Open firewall for postgresql
Use one of the hostnames in /etc/hosts that pointed to the ip of my host. This hostname for me was: host.docker.internal
This issue can be fixed in two possible ways
Specify the host and user name explicitly
psql -h localhost -U postgres
Or
Navigate to the runpsql.sh file and run the query
/Library/PostgreSQL/14/scripts/runpsql.sh
Now run the psql query by entering password (if needed)

Ncrack just do nothing after launching command

I am pentesting my host using ncrack
I use such command ncrack -U login.txt -P pass.txt -iL ipList.txt -p 3389
After launching it shows me that ncrack has started and nothing happens.
What is the problem please help
This question should be on Security Stackexchange. Anyway, try to change 3389 for rdp.
You can try too removing the list using only one ip to test:
ncrack -vv -U login.txt -P pass.txt x.x.x.x:3389 where x.x.x.x is one of the ips of your list. With -vv you will see more verbose output to find out the error.
Are you sure your ips and/or hostnames on ipList.txt are accesible by network on tcp port 3389?
If not, it is a network problem.

mail is not working on my PC

Tried to send an email to myself in a bash script from Ubuntu (12.04) command line, it will not send. I even used wireshark to snoop traffic on port 25, don't even see tcp session got established.
mail -s "Subject" xxxxx#yahoo.com < msg.txt
It's supposed to be very simple: just find the server from the email address (xxxxx#yahoo.com), set up a TCP connection and follow the SMTP protocol. It doesn't even try to establish an TCP connection.
Any ideas? Thanks.
use the sendmail program. It's a lot simpler :)
sudo apt-get install sendmail
sudo sendmailconfig
echo testmail | sendmail address#gmail.com

How to specify port number when sending mail with postfix?

I've uncommented the 'submission' line in master.cf and I can 'telnet example.com 587' on my mail server with no problem but how do I send mail from the command line of the client to the postfix server over port 587?
My server is hosted as a digitalocean droplet (centos instance) on the internet and my client is my home laptop.
Each time I try to deliver a message with the 'mail user#example.com' command I instantly receive a rejection message because my isp blocks port 25.
Any help greatly appreciated :)
mail command will drop the mail to the SMTP server running on your home laptop and the SMTP server running on your home laptop is not configured i guess. So it is trying to deliver the mail by doing an MX lookup (i.e to port 25 of your MX server). If you want to do any smtp tests please try using swaks tool.
# For eg. to authenticate and send mail from your mail server, you will have to use
swaks -f you#example.com -t someone#yahoo.com -s example.com -p 587 --auth-user you#example.com --auth-pass somepass
# -f from
# -t to
# -s server
# -p port
# --auth-user username
# --auth-pass password
More info here Hope that helps.

psql cant connect to PostgreSQL server (postmaster) on IP and port 5432?

Please read before replying it as duplicate (as it perhaps can happen). I am running my postmaster (postgres) server. See below for 'sudo netstat -anp|grep 5432' output?
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 29606/postmaster
unix 2 [ ACC ] STREAM LISTENING 1650581 29606/postmaster /var/run/postgresql/.s.PGSQL.5432
unix 2 [ ACC ] STREAM LISTENING 1650582 29606/postmaster /tmp/.s.PGSQL.5432
I am able to connect from localhost using
psql -h localhost (OR 127.0.0.1) -d <DB> -U user -W
But when I try to connect from other hosts using tcp, by specifying
psql -h ip_add_postmaster -d <DB> -U user -W
It throws:
psql: could not connect to server: Connection refused
Is the server running on host XXXXXX and accepting TCP/IP connections on port 5432?
What's wrong here?
pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
In postgresql.conf,
listen_addresses = 'localhost, 127.0.0.1, ip_add_postmaster'
Note: ip_add_postmaster is same as my Elastic IP and not public DNS. If this information
matters.
What am I doing wrong here? Machine is hosted on Amazon EC2 and have open the port 5432.
As your netstat output indicates, it's listening at 127.0.0.1:5432 which is localhost. That is only connectable from localhost ;)
Set listen_addresses='*' in your config and it will work.
[edit]
Other things to check:
is the amazon firewall blocking anything?
is iptables blocking anything?
But first make sure the listening address is correct, your netstat output shows that it won't work like this.
listen_addresses='localhost, private_ip' fixed the issue. I was not able to start postmaster server on elastic IPs. Once postgres server started o localhost and private IPs, I was able to connect.
One other issue I have found was if you end up with two Postgres installations, the second one can choose non-default port (in my case it was 5433 i/o 5432). So checking the port in postgresql.conf might be a good idea.
I ran into this issue and tried all sorts of fixes I found across SO, and want to add a simple solution that worked for me after realizing it had to do with permissions in my case.
Simply, if you're running a psql server on Windows, you are initially restricted to the default postgres superuser for logging in, launching the server, and so on.
So, first try running from the command line:
psql -U postgres -h localhost -p 5432
and enter your password at the prompt. If you've managed to login and the server is up, then it was a permissions issues. From here, you can create a role for yourself that has login privileges to whatever database you are trying to run.
If the error persists, then consider checking postgresql.conf as mentioned above, to make sure default IP is set to * or localhost, and the port set to 5432 or whatever port you want as default.
I also ran into the same issue. On debugging, it was nothing related to the port, but due to some missing directories in the Postgres folder.
While updating Mac OS (from 10.13.1 -> 10.13.13), some folders in the directory /usr/local/var/postgres/ gets deleted. The fix was the adding the missing directories:
mkdir /usr/local/var/postgres/pg_tblspc
mkdir /usr/local/var/postgres/pg_twophase
mkdir /usr/local/var/postgres/pg_stat
mkdir /usr/local/var/postgres/pg_stat_tmp
mkdir /usr/local/var/postgres/pg_replslot
mkdir /usr/local/var/postgres/pg_snapshots
mkdir /usr/local/var/postgres/pg_logical/{snapshots,mappings}