├── README.md ├── bin ├── 1-banner.png ├── 2-error.png ├── 3-variables.png ├── 4-Script-fix.png ├── 5-Script-fix.png ├── Little-tux-msfdb-fix.png ├── Script-Improbable-exec-error-1.png └── Script-Improbable-exec-error-2.png └── postgresql-fix.sh /README.md: -------------------------------------------------------------------------------- 1 | [![Version](https://img.shields.io/badge/postgresql_fix-1.4-brightgreen.svg?maxAge=259200)]() 2 | [![Stage](https://img.shields.io/badge/Release-Stable-brightgreen.svg)]() 3 | [![Build](https://img.shields.io/badge/Supported_OS-kali,Ubuntu-blue.svg)]() 4 | 5 | 6 | ![postgresql-fix v1.4](http://1.1m.yt/CqtQI1e.png) 7 | 8 | 9 | ## Postgresql-fix v1.4 - msfdb connection bugfix 10 | Version release: v1.4 (Stable) 11 | Author: pedro ubuntu [ r00t-3xp10it ] 12 | CodeName: Metasploit_postgresql_database_connection_fix 13 | Distros Supported : Linux Ubuntu, Kali, Mint, Parrot OS 14 | Suspicious-Shell-Activity (SSA) RedTeam develop @2017 15 | 16 |

17 | 18 | ## Description: 19 | This tool will try to quickly fix the metasploit postgresql connection bug, 20 | present in postgresql.conf install versions from 9.1 to 9.7 (Incorrect port settings). 21 | 'Just run it before using metasploit to check settings OR fix msfdb connection errors' 22 | ![postgresql-fix v1.4](http://3.1m.yt/HxhuFoF.png) 23 | 24 | This module will seach in postgresql.conf for port settings, and change it to the 25 | correct port configuration needed by msfdb (5432), it starts postgresql service and 26 | check's if the LocalHost its also connected to the correct port (5432), For last it 27 | check's if msfdb its connected to postgresql, if not, It will then rebuild the msfdb 28 | (database.yml) exit script execution and leave the postgresql service running. 29 | 30 | This module allows users to config a diferent port (5432) to be used, and a diferent 31 | postgresql installation path (/etc/postgresql) Users just need to edit the script 32 | and modify the values 'PoRt' and 'RoOt' in 'Tool variable declarations' funtion. 33 | ![postgresql-fix v1.4](http://2.1m.yt/tPOL7Vh.png) 34 | 35 | 36 |

37 | 38 | ## Possible errors encounter in configurations 39 | Incorrect postgresql port configuration setting 40 | ![Postgresql-fix v1.4](http://1.1m.yt/3FJOy-d.png) 41 | Postgresql selected, no connection .. 42 | ![Postgresql-fix v1.4](http://2.1m.yt/So80mg-.png) 43 | 44 |
45 | 46 | ## Improbable script execution errors 47 | Is your postgresql.conf installed in a diferent path? 48 | ![Postgresql-fix v1.4](http://3.1m.yt/WGk3Whl.png) 49 | 50 |

51 | 52 | ## Dependencies/Limitations: 53 | Zenity, Metasploit, Postgresql, Sed(bash) 54 | 55 | WARNING: Only Linux distros are supported 56 | WARNING: Only Postgresql versions from 9.1 to 9.7 57 | WARNING: This toll will NOT fix permanently the issue. 58 | 'Provides a fast way to check/fix the msfdb connection, before using msf' 59 | 60 |

61 | 62 | ## Download/Install/Config: 63 | 1º - Download framework from github 64 | git clone https://github.com/r00t-3xp10it/postgresql-fix.git 65 | 66 | 2º - Set files execution permitions 67 | cd msfdb-fix 68 | sudo chmod +x *.sh 69 | 70 | 3º - Run main tool 71 | sudo ./postgresql-fix.sh 72 | 73 |

74 | 75 | ## Video tutorials: 76 | Postgresql-fix [ Official release - Main funtions ]: https://www.youtube.com/watch?v=EGOgzm7fpEk 77 | 78 |
79 | 80 | ### Special thanks: 81 | 82 | **Suspicious-Shell-Activity (SSA) RedTeam develop @2017** 83 | -------------------------------------------------------------------------------- /bin/1-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/1-banner.png -------------------------------------------------------------------------------- /bin/2-error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/2-error.png -------------------------------------------------------------------------------- /bin/3-variables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/3-variables.png -------------------------------------------------------------------------------- /bin/4-Script-fix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/4-Script-fix.png -------------------------------------------------------------------------------- /bin/5-Script-fix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/5-Script-fix.png -------------------------------------------------------------------------------- /bin/Little-tux-msfdb-fix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/Little-tux-msfdb-fix.png -------------------------------------------------------------------------------- /bin/Script-Improbable-exec-error-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/Script-Improbable-exec-error-1.png -------------------------------------------------------------------------------- /bin/Script-Improbable-exec-error-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r00t-3xp10it/postgresql-fix/b4f03e9e2d66d9fb8dca81454e31aaf3b04fd6fb/bin/Script-Improbable-exec-error-2.png -------------------------------------------------------------------------------- /postgresql-fix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## 3 | # Version release: v1.4 (Stable) 4 | # Author: pedr0 Ubuntu [r00t-3xp10it] 5 | # codename: Metasploit_postgresql_database_connection_fix 6 | # Distros Supported : Linux Ubuntu, Kali, Mint, Parrot OS 7 | # Suspicious-Shell-Activity (SSA) RedTeam develop @2017 8 | # --- 9 | # [DESCRIPTION] 10 | # This tool will try to quickly fix the metasploit postgresql connection bug, 11 | # present in postgresql.conf install versions from 9.1 to 9.7 (Incorrect port settings). 12 | # 'Just run it before using metasploit to check settings OR fix msfdb connection errors' 13 | # 14 | # This module will seach in postgresql.conf for port settings, and change it to the 15 | # correct port configuration needed by msfdb (5432), it starts postgresql service and 16 | # check's if the LocalHost its also connected to the correct port (5432), For last it 17 | # check's if msfdb its connected to postgresql, if not, It will then rebuild the msfdb 18 | # (database.yml) exit script execution and leave the postgresql service running. 19 | # 20 | # This module allows users to config a diferent port (5432) to be used, and a diferent 21 | # postgresql installation path (/etc/postgresql) Users just need to edit the script 22 | # and modify the values 'PoRt' and 'RoOt' in 'Tool variable declarations' funtion. 23 | # --- 24 | # [DEPENDENCIES] 25 | # Zenity | Metasploit | Postgresql | Sed(bash) 26 | ## 27 | 28 | 29 | 30 | # 31 | # Tool variable declarations ________ 32 | # | 33 | VeR="1.4" # Script version number 34 | PoRt="5432" # Port used by metasploit to connect to postgresql 35 | RoOt="/etc/postgresql" # Path to postgresql instalation (version search) 36 | SeRvIcE="service postgresql start" # Command used to start the postgresql service 37 | DiStRo=`awk '{print $1}' /etc/issue` # Store distribution - Ubuntu or Kali 38 | BYpAsS="NO" # Bypass LocaHost checks (127.0.0.1:5432) 39 | ##___________________________________| 40 | 41 | 42 | 43 | 44 | # 45 | # Resize terminal windows size before running the tool (gnome terminal) 46 | # Special thanks to h4x0r Milton@Barra for this little piece of heaven! :D 47 | # 48 | resize -s 26 92 > /dev/null 49 | 50 | 51 | 52 | # 53 | # Colorise shell Script output leters 54 | # 55 | Colors() { 56 | Escape="\033"; 57 | white="${Escape}[0m"; 58 | RedF="${Escape}[31m"; 59 | GreenF="${Escape}[32m"; 60 | YellowF="${Escape}[33m"; 61 | BlueF="${Escape}[34m"; 62 | CyanF="${Escape}[36m"; 63 | Reset="${Escape}[0m"; 64 | } 65 | 66 | 67 | 68 | # 69 | # check if user is root (admin) 70 | # 71 | if [ $(id -u) != "0" ]; then 72 | echo "[☠] we need to be root to run this script..." 73 | echo "[☠] execute [ sudo ./postgresql.sh ] on terminal" 74 | exit 75 | fi 76 | 77 | 78 | 79 | # 80 | # Tool main Banner display 81 | # 82 | Colors; 83 | echo ${BlueF} 84 | cat << ! 85 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---+ 86 | |p|o|s|t|g|r|e|s|q|l|-|f|i|x|:|$VeR| 87 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---+ 88 | Author: r00t-3xp10it [ssa-red_team] 89 | 90 | ! 91 | 92 | 93 | 94 | # 95 | # Store postgresql.conf full PATH into one bash variable .. 96 | # Only the lastest version installed of postgresql will be locked .. 97 | # 98 | # check attacker version OS to config path 99 | if [ "$DiStRo" = "Ubuntu" ]; then 100 | echo ${BlueF}[☆]${white}" $DiStRo OS distribution found .."${Reset}; 101 | echo ${BlueF}[☆]${white}" Storing postgresql.conf full path .."${Reset}; 102 | 103 | # 104 | # Trying to locate the latest version installed (Ubuntu).. 105 | # 106 | path=`locate postgresql.conf | grep "/opt" | grep "/data"` 107 | if [ "$path" = "$RoOt/data/postgresql.conf" ]; then 108 | postgresql_path="$RoOt/data/postgresql.conf" 109 | fi 110 | 111 | # 112 | # Config setting for Parrot system (shanty bug-report) 113 | # 114 | elif [ "$DiStRo" = "Parrot" ]; then 115 | echo ${BlueF}[☆]${white}" $DiStRo OS distribution found .."${Reset}; 116 | echo ${BlueF}[☆]${white}" Storing postgresql.conf full path .."${Reset}; 117 | # find the correct version installed 118 | if [ -e "$RoOt/9.1/main/postgresql.conf" ]; then 119 | postgresql_path="$RoOt/9.1/main/postgresql.conf" 120 | elif [ -e "$RoOt/9.2/main/postgresql.conf" ]; then 121 | postgresql_path="$RoOt/9.2/main/postgresql.conf" 122 | elif [ -e "$RoOt/9.3/main/postgresql.conf" ]; then 123 | postgresql_path="$RoOt/9.3/main/postgresql.conf" 124 | elif [ -e "$RoOt/9.4/main/postgresql.conf" ]; then 125 | postgresql_path="$RoOt/9.4/main/postgresql.conf" 126 | elif [ -e "$RoOt/9.5/main/postgresql.conf" ]; then 127 | postgresql_path="$RoOt/9.5/main/postgresql.conf" 128 | elif [ -e "$RoOt/9.6/main/postgresql.conf" ]; then 129 | postgresql_path="$RoOt/9.6/main/postgresql.conf" 130 | elif [ -e "$RoOt/9.7/main/postgresql.conf" ]; then 131 | postgresql_path="$RoOt/9.7/main/postgresql.conf" 132 | elif [ -e "$RoOt/11/main/postgresql.conf" ]; then 133 | postgresql_path="$RoOt/11/main/postgresql.conf" 134 | else 135 | echo ${RedF}[x]${white}" Postgresql.conf path not found .."${Reset}; 136 | sleep 1 137 | echo ${RedF}[x]${white}" Path sellected: $RoOt/../main/postgresql.conf" ${Reset}; 138 | sleep 2 139 | echo ${RedF}[x]${white}" Script execution aborted .."${Reset}; 140 | sleep 1 141 | echo ${BlueF}[☆]${white}" Edit this script and change the 'RoOt' variable .."${Reset}; 142 | sleep 1 143 | # Abort script execution .. 144 | exit 145 | fi 146 | 147 | 148 | else 149 | 150 | # 151 | # Trying to locate the latest version installed (Kali).. 152 | # 153 | echo ${BlueF}[☆]${white}" $DiStRo OS distribution found .."${Reset}; 154 | echo ${BlueF}[☆]${white}" Storing postgresql.conf full path .."${Reset}; 155 | path=`locate postgresql.conf | grep "/etc" | grep "9.1"` 156 | if [ "$path" = "$RoOt/9.1/main/postgresql.conf" ]; then 157 | postgresql_path="$RoOt/9.1/main/postgresql.conf" 158 | fi 159 | path=`locate postgresql.conf | grep "/etc" | grep "9.2"` 160 | if [ "$path" = "$RoOt/9.2/main/postgresql.conf" ]; then 161 | postgresql_path="$RoOt/9.2/main/postgresql.conf" 162 | fi 163 | path=`locate postgresql.conf | grep "/etc" | grep "9.3"` 164 | if [ "$path" = "$RoOt/9.3/main/postgresql.conf" ]; then 165 | postgresql_path="$RoOt/9.3/main/postgresql.conf" 166 | fi 167 | path=`locate postgresql.conf | grep "/etc" | grep "9.4"` 168 | if [ "$path" = "$RoOt/9.4/main/postgresql.conf" ]; then 169 | postgresql_path="$RoOt/9.4/main/postgresql.conf" 170 | fi 171 | path=`locate postgresql.conf | grep "/etc" | grep "9.5"` 172 | if [ "$path" = "$RoOt/9.5/main/postgresql.conf" ]; then 173 | postgresql_path="$RoOt/9.5/main/postgresql.conf" 174 | fi 175 | path=`locate postgresql.conf | grep "/etc" | grep "9.6"` 176 | if [ "$path" = "$RoOt/9.6/main/postgresql.conf" ]; then 177 | postgresql_path="$RoOt/9.6/main/postgresql.conf" 178 | fi 179 | path=`locate postgresql.conf | grep "/etc" | grep "9.7"` 180 | if [ "$path" = "$RoOt/9.7/main/postgresql.conf" ]; then 181 | postgresql_path="$RoOt/9.7/main/postgresql.conf" 182 | fi 183 | path=`locate postgresql.conf | grep "/etc" | grep "11"` 184 | if [ "$path" = "$RoOt/11/main/postgresql.conf" ]; then 185 | postgresql_path="$RoOt/11/main/postgresql.conf" 186 | fi 187 | fi 188 | 189 | 190 | # 191 | # Confirm if the tool has stored correctly the postgresql.conf full PATH .. 192 | # 193 | if ! [ -e "$postgresql_path" ]; then 194 | echo ${RedF}[x]${white}" Postgresql.conf path not found .."${Reset}; 195 | sleep 1 196 | echo ${RedF}[x]${white}" Path sellected: $RoOt/../main/postgresql.conf" ${Reset}; 197 | sleep 2 198 | echo ${RedF}[x]${white}" Script execution aborted .."${Reset}; 199 | sleep 1 200 | echo ${BlueF}[☆]${white}" Edit this script and change the 'RoOt' variable .."${Reset}; 201 | sleep 1 202 | # Abort script execution .. 203 | exit 204 | fi 205 | # 206 | # Display to user the posgresql (latest version) full path locked .. 207 | # 208 | echo ${GreenF}[✔]${white}" Path": $postgresql_path ${Reset}; 209 | sleep 1 210 | 211 | 212 | 213 | # 214 | # Store postgresql PORT used into one bash variable .. 215 | # 216 | echo ${BlueF}[☆]${white}" Storing postgresql port configuration .."${Reset}; 217 | port=`grep "port =" $postgresql_path | awk {'print $3'}` 218 | sleep 1 219 | 220 | if [ "$port" != "$PoRt" ]; then 221 | # 222 | # Postgresql Incorrect PORT configuration found .. 223 | # 224 | echo ${RedF}[x]${white}" Postgresql Incorrect port configuration .."${Reset}; 225 | sleep 1 226 | echo ${RedF}[x]${white}" Postgresql Port found:${RedF}$port${white} .."${Reset}; 227 | sleep 1 228 | # 229 | # Use SED(bash) to replace the PORT number in postgresql.conf .. 230 | # 231 | echo ${RedF}[x]${white}" Replacing port number in postgresql.conf .."${Reset}; 232 | sed -i "s|port = $port|port = $PoRt|" $postgresql_path 233 | sleep 1 234 | # Re-define PORT variable(bash) to be used further ahead .. 235 | port="$PoRt" 236 | echo ${GreenF}[✔]${white}" Postgresql port":${GreenF}$port ${Reset}; 237 | sleep 1 238 | else 239 | # 240 | # All good in postgresql PORT settings found .. 241 | # 242 | echo ${GreenF}[✔]${white}" Postgresql port":${GreenF}$port ${Reset}; 243 | sleep 1 244 | fi 245 | 246 | 247 | # 248 | # Start postgresql service .. 249 | # 250 | echo ${BlueF}[☆]${white}" Starting postgresql service .."${Reset}; 251 | $SeRvIcE | zenity --progress --pulsate --title "☠ PLEASE WAIT ☠" --text="Starting postgresql service .." --percentage=0 --auto-close --width 300 > /dev/null 2>&1 252 | echo ${GreenF}[✔]${white}" Service postgresql running .."${Reset}; 253 | sleep 1 254 | 255 | 256 | # 257 | # Store LocalHost settings into one enviroment variable .. 258 | # 259 | check=`ss -ant | grep "127" | grep "$port" | awk {'print $4'} | cut -d ':' -f2` 260 | print=`ss -ant | grep "127" | grep "$port" | awk {'print $4'}` 261 | nill=`ss -ant | grep "127" | awk {'print $4'}` 262 | 263 | # 264 | # Bypass or NOT the use of LocalHost checks .. 265 | # 266 | if [ "$BYpAsS" = "NO" ]; then 267 | echo ${BlueF}[☆]${white}" Checking LocalHost connection status .."${Reset}; 268 | sleep 1 269 | 270 | if [ "$check" != "$port" ]; then 271 | # 272 | # LocalHost Incorrect configuration found .. 273 | # (LocalHost) postgresql PORT open not found, aborting tasks .. 274 | # 275 | echo ${RedF}[x]${white}" LocalHost Incorrect configuration found .."${Reset}; 276 | echo ${RedF}[x]${white}" LocalHost settings: $nill "${Reset}; 277 | sleep 1 278 | echo ${RedF}[x]${white}" Script execution aborted .."${Reset}; 279 | # Abort script execution .. 280 | exit 281 | 282 | else 283 | 284 | # 285 | # All good in postgresql PORT open (LocalHost) .. 286 | # Start msfconsole to check postgresql connection status 287 | # 288 | echo ${GreenF}[✔]${white}" LocalHost settings: $print "${Reset}; 289 | sleep 1 290 | echo ${BlueF}[☆]${white}" Checking msfdb connection status .."${Reset}; 291 | ih=`msfconsole -q -x 'db_status; exit -y' | grep "postgresql" | awk {'print $2'}` 292 | 293 | # 294 | # Postgresql selected, no connection .. 295 | # 296 | if [ "$ih" != "connected" ]; then 297 | echo ${RedF}[x]${white}" postgresql selected, no connection .."${Reset}; 298 | echo ${RedF}[x]${white}" Please wait, rebuilding msf database .."${Reset}; 299 | sleep 1 300 | # 301 | # Rebuild msf database (database.yml) 302 | # 303 | echo "" 304 | msfdb reinit | zenity --progress --pulsate --title "☠ PLEASE WAIT ☠" --text="Rebuild metasploit database" --percentage=0 --auto-close --width 300 > /dev/null 2>&1 305 | echo "" 306 | echo ${GreenF}[✔]${white}" postgresql connected to msf .."${Reset}; 307 | sleep 1 308 | else 309 | # 310 | # All good in Postgresql connection to Metasploit database .. 311 | # 312 | echo ${GreenF}[✔]${white}" postgresql connected to msf .."${Reset}; 313 | sleep 1 314 | fi 315 | fi 316 | 317 | else 318 | 319 | echo ${YellowF}[☠]${white}" LocalHost checks:${RedF} Bypassed${white} .."${Reset}; 320 | echo ${YellowF}[☠]${white}" LocalHost settings: $print "${Reset}; 321 | sleep 1 322 | echo ${BlueF}[☆]${white}" Checking msfdb connection status .."${Reset}; 323 | ih=`msfconsole -q -x 'db_status; exit -y' | awk {'print $3'}` 324 | 325 | # 326 | # Postgresql selected, no connection .. 327 | # 328 | if [ "$ih" != "connected" ]; then 329 | echo ${RedF}[x]${white}" postgresql selected, no connection .."${Reset}; 330 | echo ${RedF}[x]${white}" Please wait, rebuilding msf database .."${Reset}; 331 | sleep 1 332 | # 333 | # Rebuild msf database (database.yml) 334 | # 335 | echo "" 336 | msfdb reinit | zenity --progress --pulsate --title "☠ PLEASE WAIT ☠" --text="Rebuild metasploit database" --percentage=0 --auto-close --width 300 > /dev/null 2>&1 337 | echo "" 338 | echo ${GreenF}[✔]${white}" postgresql connected to msf .."${Reset}; 339 | sleep 1 340 | else 341 | # 342 | # All good in Postgresql connection to Metasploit database .. 343 | # 344 | echo ${GreenF}[✔]${white}" postgresql connected to msf .."${Reset}; 345 | sleep 1 346 | fi 347 | 348 | 349 | fi 350 | 351 | 352 | 353 | # 354 | # The end .. 355 | # 356 | echo ${BlueF}[☆]${white}" Script execution completed .."${Reset}; 357 | sleep 1 358 | echo "" 359 | echo ${white}" Author${BlueF}::${white}pedr0 ubuntu${BlueF}::${white}[r00t-3xp10it]"${Reset}; 360 | echo ${white}" Codename${BlueF}::${white}Metasploit_postgresql_database_connection_fix"${Reset}; 361 | echo ${white}" postgresql-fix${BlueF}::${white}v$VeR${BlueF}::${white}SuspiciousShellActivity©${BlueF}::${white}RedTeam${BlueF}::${white}2017"${Reset}; 362 | echo "" 363 | exit 364 | 365 | --------------------------------------------------------------------------------