All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
We understood from your question that those people bought shares in a bill-brokerage company that does not adhere to the Sharee'ah in its dealings by being a broker for companies, whether they deal in Riba or unlawful activities or not.
Undoubtedly, buying shares in such companies which do not adhere to Sharee‘ah rules is unlawful because their work supports the occurrence of Riba and unlawful activities; Allaah Almighty says (what means): {but do not cooperate in sin and aggression.} [Quran 5:2] Whoever does so must repent to Allaah and seek His Forgiveness and withdraw from such companies by taking only his capital without any gains.
If the people running the company do not accept withdrawal and oblige the withdrawing person to sell the shares according to the current market price, then, there is a problem in this regard. If the person sells the shares, he helps others to get involved in what is unlawful. If he remains a shareholder, he remains involved in what is unlawful. So, what is the way out? The answer is that the person should continue in the company and give the amount of money which he believes to be gained from dealing in what is unlawful in charity.
Buying shares in the companies that conduct lawful activities but take Riba-based loans is impermissible because one of the conditions of buying shares in companies is that they do not give or take loans on the basis of Riba.
Allaah Knows best.