Current time: 11-05-2024, 09:00 PM Hello There, Guest! (LoginRegister)


Post Reply 
[Shell] Decrypt Mailpasswords
Author Message
Knut Offline
Member
***

Posts: 736
Joined: Nov 2006
Reputation: 10
Post: #1
[Shell] Decrypt Mailpasswords
In some cases, I need the decrypted password of a user's mail.
To make it easier for me, I have written a small php-shell-script.

Here we go:
(of course you need php-cli)

1. Save this code over here -> /root/bin
PHP Code:
#!/usr/bin/php -q

<?php

## Autor: Knut Herter
## Datum: 06.10.2009
## Web  : http://www.systemtechnics.de
##
## Usage: decrypt_mailpw.php |grep whatever_you_want
##
## Example: decrypt_mailpw.php |grep admin


###
# FIRST CHANGE THIS VALUES !
###

$SQLHST  "localhost";
$SQLUSR  "root";
$ISPCPDB "ispcp";

# if error_reporting on, you see some session errors at cli
error_reporting(0);

#################################
#### Do not change from here ####

echo "MySQL password for $SQLUSR@$SQLHST: ";
system('stty -echo');
$SQLPW trim(fgets(STDIN));
system('stty echo'); 

$QUERY "
        SELECT  `mail_users`.mail_acc,
                `mail_users`.mail_pass,
                `domain`.domain_name

        FROM    `domain`

        INNER JOIN `mail_users` ON (`mail_users`.domain_id = `domain`.domain_id)

        WHERE   `mail_type` LIKE 'normal_mail' OR `mail_type` LIKE 'normal_mail,normal_forward'"
;

require 
'/var/www/ispcp/gui/include/ispcp-lib.php';

$link mysql_connect$SQLHST$SQLUSR$SQLPW);
if (!
$link) {
    die(
'keine Verbindung möglich: ' mysql_error());
}

mysql_select_db$ISPCPDB$link) or die('Could not select database.');

$result mysql_query($QUERY);
if (!
$result) {
    die(
'Ungültige Abfrage: ' mysql_error());
}

$FORMAT "Domain MailAdr: [ %s@%s ] Passwort: [ %s ]\n";
while (
$row mysql_fetch_row($result)) {
    
printf $FORMAT$row[0], $row[2],  decrypt_db_password ($row[1]));
}
printf ("\n");

mysql_close($link);

####### DOMAINALIASE

$QUERY "
        SELECT  `mail_users`.mail_acc,
                `mail_users`.mail_pass,
                `domain_aliasses`.alias_name

        FROM    `domain_aliasses`

        INNER JOIN `mail_users` ON (`mail_users`.sub_id = `domain_aliasses`.alias_id)

        WHERE   `mail_type` LIKE 'alias_mail' OR `mail_type` LIKE 'alias_mail,alias_forward'"
;



$link mysql_connect$SQLHST$SQLUSR$SQLPW);
if (!
$link) {
    die(
'keine Verbindung möglich: ' mysql_error());
}

mysql_select_db$ISPCPDB$link) or die('Could not select database.');

$result mysql_query($QUERY);
if (!
$result) {
    die(
'Ungültige Abfrage: ' mysql_error());
}


$FORMAT "Aliasdomain MailAdr: [ %s@%s ] Passwort: [ %s ]\n";
while (
$row mysql_fetch_row($result)) {
    
printf $FORMAT$row[0], $row[2],  decrypt_db_password ($row[1]));
}
printf ("\n");

mysql_close($link); 

2. make it executable
Code:
chmod +x /root/bin/decrypt_mailpw.php

3. run :-)

4. If you want a special mailpassword, run with grep
example:
Code:
decrypt_mailpw.php |grep webmaster
or
Code:
decrypt_mailpw.php |grep mydomain.de
(This post was last modified: 10-06-2009 05:09 PM by Knut.)
01-21-2009 03:59 AM
Find all posts by this user Quote this message in a reply
fulltilt Offline
Member
***

Posts: 1,225
Joined: Apr 2007
Reputation: 5
Post: #2
RE: [Shell] Decrypt Mailpasswords
(01-21-2009 03:59 AM)Knut Wrote:  In some cases, I need the decrypted password of a user's mail.
To make it easier for me, I have written a small php-shell-script.

thanks - very nice :-)
01-23-2009 04:54 PM
Find all posts by this user Quote this message in a reply
Kotty Offline
Junior Member
*

Posts: 167
Joined: Mar 2008
Reputation: 3
Post: #3
RE: [Shell] Decrypt Mailpasswords
Hi,

that
WHERE `mail_type` LIKE 'normal_mail'";
should be,
WHERE `mail_type` = 'normal_mail' OR mail_type = 'normal_mail,normal_forward'";
01-26-2009 05:22 PM
Find all posts by this user Quote this message in a reply
Knut Offline
Member
***

Posts: 736
Joined: Nov 2006
Reputation: 10
Post: #4
RE: [Shell] Decrypt Mailpasswords
Yes you're right.
I've changed
01-26-2009 05:28 PM
Find all posts by this user Quote this message in a reply
freinhard Offline
Junior Member
*

Posts: 39
Joined: Apr 2009
Reputation: 0
Post: #5
RE: [Shell] Decrypt Mailpasswords
since i dont like hardcoded passwords:

PHP Code:
echo "MySQL password for $SQLUSER@$SQLHST: ";
system('stty -echo');
$SQLPW trim(fgets(STDIN));
system('stty echo'); 
04-17-2009 07:33 PM
Find all posts by this user Quote this message in a reply
Knut Offline
Member
***

Posts: 736
Joined: Nov 2006
Reputation: 10
Post: #6
RE: [Shell] Decrypt Mailpasswords
OK, it's changed above.

Thx
04-17-2009 07:42 PM
Find all posts by this user Quote this message in a reply
Knut Offline
Member
***

Posts: 736
Joined: Nov 2006
Reputation: 10
Post: #7
RE: [Shell] Decrypt Mailpasswords
EDIT: Domain Alias enhancement, update at first Post
10-06-2009 05:11 PM
Find all posts by this user Quote this message in a reply
gOOvER Offline
Banned

Posts: 3,561
Joined: Jul 2007
Post: #8
RE: [Shell] Decrypt Mailpasswords
I will add it to the Wiki tonight, so you only have to change it there. Smile
10-06-2009 05:15 PM
Visit this user's website Find all posts by this user Quote this message in a reply
elitepilot Offline
Member
***

Posts: 352
Joined: Feb 2008
Reputation: 0
Post: #9
RE: [Shell] Decrypt Mailpasswords
how long does the script work?
10-25-2009 12:10 AM
Find all posts by this user Quote this message in a reply
rethus Offline
Junior Member
*

Posts: 202
Joined: May 2009
Reputation: 3
Post: #10
RE: [Shell] Decrypt Mailpasswords
Hi Knut,
nice that you post your scripts. And i see your other nice scripts for munin. Maybe i give them a try, if i setup munin soon.

But watch out with German Law. Im Germany it's didn't allow to decrypt user passwords without their agreement - even if its in on your own Server, or in your own application.
Nevertheless, its a nice script, maybe to create an automated email-password-reminder.
(This post was last modified: 12-04-2010 11:21 AM by rethus.)
12-04-2010 11:20 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)