Section 18. If an insured person enters into a contract, written or oral, with an independent contractor to do such person's work, or if such a contractor enters into a contract with a sub-contractor to do all or any part of the work comprised in such contract with the insured, and the insurer would, if such work were executed by employees immediately employed by the insured, be liable to pay compensation under this chapter to those employees, the insurer shall pay to such employees any compensation which would be payable to them under this chapter if the independent or sub-contractors were insured persons. The insurer, however, shall be entitled to recover indemnity from any other person who would have been liable to such employees independently of this section; and if the insurer has paid compensation under this section, it may enforce, in the name of the employee or in its own name and for its benefit, the liability of such other person. The insurer shall also be entitled to recover from the uninsured independent contractor or the uninsured sub-contractor all compensation benefits and expenses, medical, hospital or otherwise, that it has paid or may become obligated to pay on account of any injury to the employee or employees of any such uninsured independent contractor or uninsured sub-contractor; provided, that this provision shall not authorize the insurer to recover from such a contractor or sub-contractor an amount which, together with any sum recovered under this chapter from any other person on account of the payment of compensation to such employee or employees, will exceed in the aggregate the amount of such compensation benefits and expenses. This section shall not apply to any contract of an independent or sub-contractor which is merely ancillary and incidental to, and is no part of or process in, the trade or business carried on by the insured, nor to any case where the injury occurred elsewhere than on, in or about the premises on which the contractor has undertaken to execute the work for the insured or which are under the control or management of the insured. The word ''premises'', as used in this section, shall include the public highways if the contract requires or necessitates the use of the public highways.
In any case where there shall exist with respect to an employee a general employer and a special employer relationship, as between the general employer and the special employer, the liability for the payment of compensation for the injury shall be borne by the general employer or its insurer, and the special employer or its insurer shall be liable for such payment if the parties have so agreed or if the general employer shall not be an insured or insured person under this chapter.