shell bypass 403

UnknownSec Shell

: /scripts/ [ drwxr-xr-x ]

name : mainipcheck
#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/mainipcheck                     Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use strict;
use warnings;

package scripts::mainipcheck;

use Cpanel::IP::LocalCheck   ();
use Cpanel::IP::Loopback     ();
use Cpanel::Linux::RtNetlink ();
use Cpanel::LoadModule       ();
use Cpanel::Logger           ();
use Cpanel::NAT::Object      ();
use Cpanel::SafeRun::Object  ();
use Cpanel::FileUtils::Write ();
use Cpanel::LoadFile         ();
use Cpanel::DIp::LicensedIP  ();
use Cpanel::Exception        ();
use Socket                   ();

use Try::Tiny;

use Getopt::Long qw(GetOptionsFromArray);

our $MAINIP_FILE = '/var/cpanel/mainip';

exit( __PACKAGE__->script( \@ARGV ) ) unless caller();

sub script {
    my ( $class, $argv ) = @_;

    my $remote_check;
    GetOptionsFromArray(
        $argv,
        'remote-check' => \$remote_check,
    ) if defined $argv and ref $argv eq 'ARRAY';

    my $logger = Cpanel::Logger->new();

    my $mainip_file_contents = eval { Cpanel::LoadFile::loadfile($MAINIP_FILE) // '' };
    my $mainip               = $mainip_file_contents =~ s/\s+//gr;
    my $myip_url             = Cpanel::DIp::LicensedIP::myip_url();
    my $cpIP                 = Cpanel::DIp::LicensedIP::get_license_ip($myip_url);
    my $default_route_ip;
    my $update_mainip      = $mainip ne $mainip_file_contents;    # Clean up formatting of the file if true
    my $mainip_file_exists = -e $MAINIP_FILE;                     # No sense in stat-ing the file twice like we used to in certain scenarioes

    # Needed for NAT awareness, is NO-OP on non-NAT to these values (thus local and public IP values would be the same on non-nat systems).
    my $NAT_obj      = Cpanel::NAT::Object->new();
    my $NAT_local_ip = $NAT_obj->get_local_ip($cpIP);

    if ($remote_check) {
        print "$cpIP\n";
        return 0;
    }

    eval { $default_route_ip = get_ip_from_netlink() || get_ip_from_default_route(); };
    if ( my $error_message = $@ ) {
        chomp $error_message;
        $logger->warn("Encountered an error while determining the main IP from the default route: $error_message");
        ($mainip_file_exists) ? die "/var/cpanel/mainip exists. Bailing out..." : $logger->info("Proceeding with main IP check assuming that the IP address from $myip_url is the main IP address.");
        $default_route_ip = $mainip;    # XXX Should we keep going even here? I'm not sure.
    }
    my $NAT_public_ip = $NAT_obj->get_public_ip($default_route_ip);

    my $canonical_main_ip = $default_route_ip || $NAT_local_ip;
    if ( !$mainip_file_exists ) {
        $update_mainip = 1;             # I'm somewhat curious as to whether we'd wanna update SPF records here too, honestly.
    }
    elsif ( $canonical_main_ip ne $mainip ) {
        $update_mainip = 1;
        $logger->info("The Server's main IP address has changed from $mainip to $canonical_main_ip.");

        # At one point, the below condition turned $default_route_ip into $cpIP, causing logger warns to actually get suppressed
        # when they would normally be spuriously reported for NATted systems.
        # This is because all the check for the logger warn below used to be if $default_route_ip ne $cpIP.
        # This would never be true when we had to update the mainip previously.
        if ( !Cpanel::IP::LocalCheck::ip_is_on_local_server($cpIP) ) {
            $logger->warn("$cpIP is not bound to an interface on the system! Please verify your network configuration.");

            # This can trigger pretty trivially on NAT setups if your cpnat configuration is not built or in fact insane.
            # Just make /var/cpanel/cpnat contain non-ip strings as if they were a key=>value nat IP pair separated
            # by spaces if you want to see this in action.
        }

        # Ensure the license system has what it needs? Not sure how it gets the updated mainip or if it even needs it?
        _reprovision_license_authn();

        require Cpanel::ServerTasks;

        # Update SPF records, as we've changed to a new mainip
        Cpanel::ServerTasks::schedule_task( ['SPFTasks'], 5, 'update_all_users_spf_records' );
        $logger->info("Scheduled SPF record update");
    }

    if ($update_mainip) {
        Cpanel::FileUtils::Write::overwrite( $MAINIP_FILE, $canonical_main_ip, 0644 );
    }

    if ( !$NAT_obj->enabled && $default_route_ip ne $cpIP ) {
        $logger->warn("$myip_url detects system IP as $cpIP and system local IP detected as $default_route_ip. Please verify your network configuration.");
    }
    elsif ( $NAT_obj->enabled && $NAT_public_ip ne $cpIP && $NAT_local_ip ne $default_route_ip ) {

        # Entertaingly enough, in this instance, $NAT_local_ip always equals $cpIP and vice versa. Conveniently enough, it also catches all invalid NAT configs.
        $logger->warn("$myip_url detects a system IP address of $cpIP and system local IP address of $default_route_ip.");
        $logger->warn("This looks like a NAT setup, but these IP addresses do not correspond to values listed in /var/cpanel/cpnat.");
        $logger->info("The system will now rebuild your cpnat configuration to ensure system sanity.");
        _system('/usr/local/cpanel/scripts/build_cpnat');
    }

    return 0;
}

# For mocking in tests -- don't remove the 'uncoverable' comments below, as this impacts Devel::Cover reporting.
sub _system {

    # uncoverable subroutine
    return system @_;    # uncoverable statement
}

# Pick a testing IP and see how the kernel proposes routing it, then look up and return the source address which would be used.
sub get_ip_from_netlink {
    my $TEST_IP   = '208.74.123.2';    # TODO: Better way of picking an IP with high probability of not being routed specially?
    my $result_ip = '';

    try {
        my $routes_ar = Cpanel::Linux::RtNetlink::get_route_to( 'AF_INET', $TEST_IP );
        foreach my $route_info_hr (@$routes_ar) {
            if ( defined $route_info_hr->{'rta_dst'} && $route_info_hr->{'rta_dst'} eq $TEST_IP ) {
                $result_ip = $route_info_hr->{'rta_prefsrc'};
                last;
            }
        }
    }
    catch {
        Cpanel::Logger->new()->warn( 'Failed to retrieve IP via Netlink: ' . Cpanel::Exception::get_string_no_id($_) . "\nFalling back to reading /proc/net/route." );
    };

    return $result_ip;
}

# Get interface associated with default route and use socket() to get IP
sub get_ip_from_default_route {
    my $proc_route_path = shift || '/proc/net/route';    # For unit testing, mostly
    my %interfaces;

    if ( open my $proc_fh, '<', $proc_route_path ) {
        while ( my $line = readline $proc_fh ) {
            chomp $line;
            if ( $line =~ m/^(.+?)\s*0{8}\s.*?(\d+)\s+0{8}\s*(?:\d+\s*){3}$/ ) {
                my ( $interface, $metric ) = ( $1, $2 );
                push @{ $interfaces{$metric} }, $interface;
            }
        }
        close($proc_fh);
    }
    else {
        die("Unable to open $proc_route_path: $!");
    }

    my $lowest_metric = ( sort keys %interfaces )[0];
    my $interface     = $interfaces{$lowest_metric}[0];
    my $ip            = get_ip_from_interface($interface);

    # VPS issues
    if ( Cpanel::IP::Loopback::is_loopback($ip) && $interface =~ /^venet0?$/ ) {
        return get_ip_from_interface('venet0:0');
    }

    return $ip;
}

sub get_ip_from_interface {
    my $interface   = shift;
    my $SIOCGIFADDR = 0x8915;
    my $proto       = getprotobyname('ip');
    socket( my $socket_fh, &Socket::PF_INET, &Socket::SOCK_DGRAM, $proto ) or die("Socket error: $!");

    # struct ifreq is 16 bytes of name, null-padded, followed by 16 bytes of answer.
    my $ifreq = pack( 'a32', $interface );
    ioctl( $socket_fh, $SIOCGIFADDR, $ifreq ) or die("Error in ioctl: $!");
    my ( $if,   $sin )  = unpack( 'a16 a16', $ifreq );
    my ( $port, $addr ) = Socket::sockaddr_in($sin);
    my $ip;
    foreach my $family ( &Socket::AF_INET, &Socket::AF_INET6 ) {
        last if $ip;

        # Generally we'll favor ipv4 addresses over ipv6, but we should use the v6 if it is the only one available.
        $ip = Socket::inet_ntop( $family, $addr );
    }
    return $ip;
}

sub _reprovision_license_authn {

    Cpanel::LoadModule::load_perl_module('Cpanel::Market');
    Cpanel::Market::set_cpstore_is_in_sync_flag(0);
    #
    # This will cause the system to get new LicenseAuthn
    # credentials so we can connect to various cPanel systems
    # that require license-based authentication.
    #
    my $run = Cpanel::SafeRun::Object->new( 'program' => '/usr/local/cpanel/cpkeyclt' );
    warn $run->autopsy() if $run->CHILD_ERROR;

    #
    #  cpkeyclt will auto re-provision on the second run
    #  if the id changes
    #
    $run = Cpanel::SafeRun::Object->new(
        'program' => '/usr/local/cpanel/scripts/try-later',
        'args'    => [
            '--action',      '/usr/local/cpanel/cpkeyclt --quiet',
            '--check',       '/bin/sh -c exit 1',
            '--delay',       11,                                     # We only allow updates every 10 minutes so wait 11
            '--max-retries', 1,
            '--skip-first'
        ]
    );
    warn $run->autopsy() if $run->CHILD_ERROR;

    #
    #  If they changed the ip for the license in manage2 they keep the
    #  same liscid so we need to check after the license update has
    #  happened the second time
    #
    $run = Cpanel::SafeRun::Object->new(
        'program' => '/usr/local/cpanel/scripts/try-later',
        'args'    => [
            '--action',      '/usr/local/cpanel/bin/check_cpstore_in_sync_with_local_storage',
            '--check',       '/bin/sh -c exit 1',
            '--delay',       15,                                                                 # Must happen after the second license update
            '--max-retries', 1,
            '--skip-first'
        ]
    );
    warn $run->autopsy() if $run->CHILD_ERROR;

    return 1;

}

© 2025 UnknownSec
Learning made Easy | Anyleson - Learning Platform
INR (₹)
India Rupee
$
United States Dollar

Joy of learning & teaching...

Rocket LMS is a fully-featured educational platform that helps instructors to create and publish video courses, live classes, and text courses and earn money, and helps students to learn in the easiest way.

6

Skillful Instructors

Start learning from experienced instructors.

11

Happy Students

Enrolled in our courses and improved their skills.

8

Live Classes

Improve your skills using live knowledge flow.

10

Video Courses

Learn without any geographical & time limitations.

Featured Courses

#Browse featured courses and become skillful

New Learning Page

Learn step-by-step tips that help you get things done with your virtual team by increasing trust and accountability.If you manage a virtual team today, then you'll probably continue to do so for the rest of your career.

5.00
20% Offer

Excel from Beginner to Advanced

Microsoft Excel is a spreadsheet developed by Microsoft for Windows, macOS, Android and iOS. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications (VBA).

4.75

Newest Courses

#Recently published courses

View All
Course
Full Stack Web Development

Full Stack Web Development

in Web Development
83:20 Hours
10 Oct 2024
₹28,318.82
Course
Installment and Secure Host

Installment and Secure Host

in Business Strategy
5.00
1:30 Hours
16 Mar 2023
₹118
Not conducted
Bestseller
New In-App Live System

New In-App Live System

in Communications
5.00
2:30 Hours
1 Mar 2026
₹11.80
Featured
New Learning Page

New Learning Page

in Lifestyle
5.00
3:30 Hours
1 Mar 2022
Free
Finished
Effective Time Management

Effective Time Management

in Management
5.00
1:30 Hours
1 Aug 2023
₹35.40
20% Offer
Excel from Beginner to Advanced

Excel from Beginner to Advanced

in Management
4.75
1:40 Hours
20 Mar 2026
₹94.40 ₹118

Latest bundles

Latest bundles subtitle

View All
Bestseller
Microsoft Office Beginner to Expert Bundle

Microsoft Office Beginner to Expert Bundle

in Management
5.00
15:10 Hours
24 Jun 2022
₹59

A-Z Web Programming

in Web Development
4.75
2:20 Hours
25 Jun 2022
₹9.44

Upcoming Courses

Courses that will be published soon

View All

Best Rated Courses

#Enjoy high quality and best rated content

View All
Finished
Effective Time Management

Effective Time Management

in Management
5.00
1:30 Hours
1 Aug 2023
₹35.40
20% Offer
Health And Fitness Masterclass

Health And Fitness Masterclass

in Health & Fitness
5.00
1:00 Hours
1 Jul 2021
₹18.88 ₹23.60
Finished
Learn Linux in 5 Days

Learn Linux in 5 Days

in Web Development
4.69
7:30 Hours
10 Jul 2021
Free
Text course
Learn Python Programming

Learn Python Programming

in Web Development
4.63
0:35 Hours
29 Jun 2021
Free
Course
Become a Product Manager

Become a Product Manager

in Business Strategy
4.58
2:30 Hours
28 Jun 2021
Free
20% Offer
Learn and Understand AngularJS

Learn and Understand AngularJS

in Web Development
3.88
1:00 Hours
10 Dec 2023
₹18.88 ₹23.60

Trending Categories

#Browse trending & popular learning topics

Bestselling Courses

#Learn from bestselling courses

View All
Course
Become a Product Manager

Become a Product Manager

in Business Strategy
4.58
2:30 Hours
28 Jun 2021
Free
Finished
Learn Linux in 5 Days

Learn Linux in 5 Days

in Web Development
4.00
7:30 Hours
10 Jul 2021
Free
20% Offer
Excel from Beginner to Advanced

Excel from Beginner to Advanced

in Management
4.75
1:40 Hours
20 Mar 2026
₹94.40 ₹118
Finished
Effective Time Management

Effective Time Management

in Management
5.00
1:30 Hours
1 Aug 2023
₹35.40
40% Offer
The Future of Energy

The Future of Energy

in Science
2.50
1:10 Hours
8 Jul 2021
₹42.48 ₹70.80
Featured
New Learning Page

New Learning Page

in Lifestyle
5.00
3:30 Hours
1 Mar 2022
Free

Free Courses

#Never miss free learning opportunities

View All
Featured
New Learning Page

New Learning Page

in Lifestyle
5.00
3:30 Hours
1 Mar 2022
Free
Course
New Update Features

New Update Features

in Language
4.00
1:30 Hours
21 Jun 2022
Free
Text course
Learn Python Programming

Learn Python Programming

in Web Development
5.00
0:35 Hours
29 Jun 2021
Free
Finished
Learn Linux in 5 Days

Learn Linux in 5 Days

in Web Development
4.00
7:30 Hours
10 Jul 2021
Free
Course
Become a Product Manager

Become a Product Manager

in Business Strategy
4.58
2:30 Hours
28 Jun 2021
Free

Discounted Courses

#Get courses at the latest price

View All
20% Offer
Excel from Beginner to Advanced

Excel from Beginner to Advanced

in Management
4.75
1:40 Hours
20 Mar 2026
₹94.40 ₹118
20% Offer
Learn and Understand AngularJS

Learn and Understand AngularJS

in Web Development
2.75
1:00 Hours
10 Dec 2023
₹18.88 ₹23.60
20% Offer
Health And Fitness Masterclass

Health And Fitness Masterclass

in Health & Fitness
5.00
1:00 Hours
1 Jul 2021
₹18.88 ₹23.60
40% Offer
The Future of Energy

The Future of Energy

in Science
2.50
1:10 Hours
8 Jul 2021
₹42.48 ₹70.80

Store Products

Explore physical & virtual products

All Products

Subscribe Now!

#Choose a subscription plan and save money!

Become an instructor

Are you interested to be a part of our community? You can be a part of our community by signing up as an instructor or organization.

Become an instructor circle dots
user name
Become an instructor start earning right now...
Have a Question? Ask it in forum and get answer circle dots

Have a Question? Ask it in forum and get answer

Our forums helps you to create your questions on different subjects and communicate with other forum users. Our users will help you to get the best answer!

Find the best instructor

Looking for an instructor? Find the best instructors according to different parameters like gender, skill level, price, meeting type, rating, etc. Find instructors on the map.

Find the best instructor circle dots
user name
Tutor Finder Find the best instructor now...

Start learning anywhere, anytime...

Use Rocket LMS to access high-quality education materials without any limitations in the easiest way.

Win Club Points
medal
You earned 50 points! for completing the course...

Win Club Points

Use Rocket LMS and win club points according to different activities. You will be able to use your club points to get free prizes and courses. Start using the system now and collect points!

Instructors

#Learn from the experienced & skillful instructors

All Instructors

Testimonials

#What our customers say about us

Ryan Newman

Ryan Newman

Data Analyst at Microsoft

"We've used Rocket LMS for the last 2  years. Thanks for the great service."

Megan Hayward

Megan Hayward

System Administrator at Amazon

"We're loving it. Rocket LMS is both perfect    and highly adaptable."

Natasha Hope

Natasha Hope

IT Technician at IBM

"I am really satisfied with my Rocket LMS. It's the perfect solution for our business."

Charles Dale

Charles Dale

Computer Engineer at Oracle

"I am so pleased with this product. I couldn't have asked for more than this."

David Patterson

David Patterson

Network Technician at Cisco

"Rocket LMS impressed me on multiple           levels."

Organizations

#Greatest education organizations are here to help you

All Organizations

Blog

#Explore latest news and articles

Blog Posts
Become a Straight-A Student 1 Jul 2021

Become a Straight-A Student

In this article, I’ll explain the two rules I followed to become a straight-A student. If you take my advice, you’ll get better grades and lead a more ...
How To Teach Your Kid Easily 1 Jul 2021

How To Teach Your Kid Easily

The primary reason kids struggle with school is fear. And in most cases, it’s their parent's fault. I started tutoring math out of financial desperation. ...
Better Relationship Between Friends 1 Jul 2021

Better Relationship Between Friends

The tutor-parent relationship is an important relationship and unfortunately greatly overlooked. Why is it important? Well, a good relationship between you and ...